public JsonResult JsCreate(Fornecedor model) { try { LogBLL.Insert(new LogDado("JsCreate", "Fornecedor", _idUsuario)); using (var db = new Context()) { using (var trans = new RP.DataAccess.RPTransactionScope(db)) { var _bll = new BLL.FornecedorBLL(db, _idUsuario); _bll.Insert(model); _bll.SaveChanges(); trans.Complete(); return Json(new { model = model }, JsonRequestBehavior.AllowGet); } } } catch (Exception ex) { Response.StatusCode = 500; return Json(RP.Util.Exception.Message.Get(ex), JsonRequestBehavior.AllowGet); } }
public ActionResult Create(FornecedorVM model) { if (string.IsNullOrEmpty(model.Cidade.nome)) { ModelState.AddModelError("Cidade.nome", "Informe a cidade"); } if (ModelState.IsValid) { try { LogBLL.Insert(new LogDado("Create", "Fornecedor", _idUsuario)); using (var db = new Context()) { using (var trans = new RP.DataAccess.RPTransactionScope(db)) { var _fornecedor = model.GetFornecedor(); var _bll = new BLL.FornecedorBLL(db, _idUsuario); _bll.Insert(_fornecedor); _bll.SaveChanges(); trans.Complete(); this.AddFlashMessage(RP.Util.Resource.Message.INSERT_SUCCESS, FlashMessage.SUCCESS); return RedirectToAction("Index"); } } } catch (Exception ex) { this.AddFlashMessage(RP.Util.Exception.Message.Get(ex), FlashMessage.ERROR); RP.Util.Entity.ErroLog.Add(ex, Session.SessionID, _idUsuario); return RedirectToAction("Index"); } } return View(model); }
public ActionResult DeleteConfirmed(int id) { try { LogBLL.Insert(new LogDado("DeleteConfirmed", "Fornecedor", _idUsuario)); using (var db = new Context()) { using (var trans = new RP.DataAccess.RPTransactionScope(db)) { var _bll = new BLL.FornecedorBLL(db, _idUsuario); _bll.Delete(e => e.idFornecedor == id); _bll.SaveChanges(); trans.Complete(); this.AddFlashMessage(RP.Util.Resource.Message.DELETE_SUCCESS, FlashMessage.SUCCESS); return RedirectToAction("Index"); } } } catch (Exception ex) { RP.Util.Entity.ErroLog.Add(ex, Session.SessionID, _idUsuario); this.AddFlashMessage(RP.Util.Exception.Message.Get(ex), FlashMessage.ERROR); RP.Util.Entity.ErroLog.Add(ex, Session.SessionID, _idUsuario); return RedirectToAction("Delete", id); } }