Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Created October 22, 2014 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpolvora/a1b70322aa41418b12ce to your computer and use it in GitHub Desktop.
Save jpolvora/a1b70322aa41418b12ce to your computer and use it in GitHub Desktop.
teste controller + repository
[HttpPost]
public ActionResult Salvar(Estoque estoque)
{
if (!ModelState.IsValid)
{
return new HttpStatusCodeResult(400, "Erros de Validação");
}
using (var unitOfWork = new CustomUnitOfWork())
{
var estoqueRepository = new EstoqueRepository(unitOfWork);
try
{
if (estoque.Id != 0)
{
estoqueRepository.Edit(estoque);
}
else
{
estoqueRepository.Add(estoque);
}
unitOfWork.Commit();
return new HttpStatusCodeResult(200);
}
catch (BusinessException bex)
{
return new HttpStatusCodeResult(400, bex.Message);
}
catch (Exception ex)
{
var msg = string.Format("Ocorreu um erro ao gravar o registro. {0}", ex.Message);
return new HttpStatusCodeResult(500, msg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment