public async Task <IActionResult> Edit(int id, [Bind("ID,Sigla,Nome,Descricao,Inativo")] SetorModel setorModel) { if (id != setorModel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(setorModel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SetorModelExists(setorModel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(setorModel)); }
/// <summary> /// Altera dados na base de dados /// </summary> /// <param name="setorModel">Dados do modelo</param> public void Editar(SetorModel setorModel) { tb_setor setorE = new tb_setor(); Atribuir(setorModel, setorE); unitOfWork.RepositorioSetor.Editar(setorE); unitOfWork.Commit(shared); }
/// <summary> /// Insere um novo na base de dados /// </summary> /// <param name="setorModel">Dados do modelo</param> /// <returns>Chave identificante na base</returns> public int Inserir(SetorModel setorModel) { tb_setor setorE = new tb_setor(); Atribuir(setorModel, setorE); unitOfWork.RepositorioSetor.Inserir(setorE); unitOfWork.Commit(shared); return(setorE.IdSetor); }
public ActionResult Edit(SetorModel setorModel) { if (ModelState.IsValid) { gSetor.Editar(setorModel); return(RedirectToAction("Index")); } return(View(setorModel)); }
public ActionResult Create(SetorModel setorModel) { if (ModelState.IsValid) { gSetor.Inserir(setorModel); return(RedirectToAction("Index")); } return(View(setorModel)); }
public void Remove(SetorModel setor) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Delete(setor); transaction.Commit(); } }
public async Task <IActionResult> Create([Bind("ID,Sigla,Nome,Descricao,Inativo")] SetorModel setorModel) { if (ModelState.IsValid) { _context.Add(setorModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(setorModel)); }
private bool IsInCollection(SetorModel Setor, ICollection <SetorModel> fromDb) { foreach (var item in fromDb) { if (Setor.Id == item.Id) { return(true); } } return(false); }
public ActionResult DeleteConfirmed(int id) { if (!Session["Perfil"].ToString().Equals("Administrador")) { return(RedirectToAction("SemPermissao", "Home", new { area = "" })); } SetorModel setormodel = db.Setores.Find(id); db.Setores.Remove(setormodel); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /Setor/Setor/Details/5 public ActionResult Details(int id = 0) { if (!Session["Perfil"].ToString().Equals("Administrador")) { return(RedirectToAction("SemPermissao", "Home", new { area = "" })); } SetorModel setormodel = db.Setores.Find(id); if (setormodel == null) { return(HttpNotFound()); } return(View(setormodel)); }
public ActionResult Create(SetorModel setormodel) { if (!Session["Perfil"].ToString().Equals("Administrador")) { return(RedirectToAction("SemPermissao", "Home", new { area = "" })); } if (ModelState.IsValid) { db.Setores.Add(setormodel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(setormodel)); }
public ActionResult Edit(SetorModel setormodel, FormCollection form) { if (!Session["Perfil"].ToString().Equals("Administrador")) { return(RedirectToAction("SemPermissao", "Home", new { area = "" })); } if (ModelState.IsValid) { db.Entry(setormodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("error", "Erro!!"); //return View(setormodel); } return(View(setormodel)); }
public void Can_add_new_Setor() { var Setor = new SetorModel { Nome = "added1", Sys_Ativo = true, Sys_DataCadastro = DateTime.Today }; ISetorRepository repository = new SetorRepository(); repository.Add(Setor); // use session to try to load the product using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get <SetorModel>(Setor.Id); // Test that the product was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(Setor, fromDb); Assert.AreEqual(Setor.Nome, fromDb.Nome); // Assert.AreEqual(Setor.Sobrenome, fromDb.Sobrenome); } }
// // GET: /setor/Edit/5 public ActionResult Edit(int id) { SetorModel setor = gSetor.Obter(id); return(View(setor)); }
// // GET: /setor/Delete/5 public ActionResult Delete(int id) { SetorModel setorModel = gSetor.Obter(id); return(View(setorModel)); }
/// <summary> /// Atribui dados do Setor Model para o Setor Entity /// </summary> /// <param name="setorModel">Objeto do modelo</param> /// <param name="setorE">Entity mapeada da base de dados</param> private void Atribuir(SetorModel setorModel, tb_setor setorE) { setorE.IdSetor = setorModel.IdSetor; setorE.Nome = setorModel.Nome; setorE.Descricao = setorModel.Descricao; }
// // GET: /setor/Details/5 public ViewResult Details(int id) { SetorModel setor = gSetor.Obter(id); return(View(setor)); }