Created
October 22, 2014 01:42
-
-
Save jpolvora/a1b70322aa41418b12ce to your computer and use it in GitHub Desktop.
teste controller + repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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