public static MaterialVM GetMaterial(Sistema.Model.Entities.Material model) { var _result = new MaterialVM { nome = model.nome, idMaterial = model.idMaterial, preco = model.preco, nrQuantidade = model.nrQuantidade, margemGanho = model.margemGanho, UnidadeMedida = Models.UnidadeMedida.Consultar.GetModel(model.UnidadeMedida), //Fabricante = Models.Fabricante.Consultar.GetModel(model.Fabricante) }; return _result; }
public ActionResult Create(MaterialVM model) { if (string.IsNullOrEmpty(model.UnidadeMedida.nome)) { ModelState.AddModelError("UnidadeMedida.nome", "Selecione uma unid. de med."); } //if (string.IsNullOrEmpty(model.Fabricante.nome)) //{ // ModelState.AddModelError("Fabricante.nome", "Selecione um fabricante"); //} if (ModelState.IsValid) { try { LogBLL.Insert(new LogDado("Create", "Material", _idUsuario)); using (var db = new Context()) { using (var trans = new RP.DataAccess.RPTransactionScope(db)) { var _material = model.GetMaterial(); var _bll = new BLL.MaterialBLL(db, _idUsuario); _bll.Insert(_material); _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 View(model); } } return View(model); }