Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
 public ActionResult Edit(SetorModel setorModel)
 {
     if (ModelState.IsValid)
     {
         gSetor.Editar(setorModel);
         return(RedirectToAction("Index"));
     }
     return(View(setorModel));
 }
Exemplo n.º 5
0
 public ActionResult Create(SetorModel setorModel)
 {
     if (ModelState.IsValid)
     {
         gSetor.Inserir(setorModel);
         return(RedirectToAction("Index"));
     }
     return(View(setorModel));
 }
Exemplo n.º 6
0
 public void Remove(SetorModel setor)
 {
     using (ISession session = NHibernateHelper.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
             session.Delete(setor);
             transaction.Commit();
         }
 }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
 private bool IsInCollection(SetorModel Setor, ICollection <SetorModel> fromDb)
 {
     foreach (var item in fromDb)
     {
         if (Setor.Id == item.Id)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
        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"));
        }
Exemplo n.º 10
0
        //
        // 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));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        //
        // GET: /setor/Edit/5

        public ActionResult Edit(int id)
        {
            SetorModel setor = gSetor.Obter(id);

            return(View(setor));
        }
Exemplo n.º 15
0
        //
        // GET: /setor/Delete/5

        public ActionResult Delete(int id)
        {
            SetorModel setorModel = gSetor.Obter(id);

            return(View(setorModel));
        }
Exemplo n.º 16
0
 /// <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;
 }
Exemplo n.º 17
0
        //
        // GET: /setor/Details/5

        public ViewResult Details(int id)
        {
            SetorModel setor = gSetor.Obter(id);

            return(View(setor));
        }