Ejemplo n.º 1
0
        public ActionResult CreateEdit(Disciplina model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //Create or Edit???
                    if (db.Disciplinas.Any(x => x.ID == model.ID))
                    {
                        db.Entry(model).State = EntityState.Modified;
                    }
                    else
                    {
                        db.Disciplinas.Add(model);
                    }

                    //Commit
                    db.SaveChanges();

                    //Msg Success
                    TempData.Add("SUCESSO", "Operação realizada com sucesso.");

                    return(RedirectToAction("CreateEdit"));
                }
            }
            catch (Exception ex)
            {
                TempData.Add("ERRO", ex.Message);
            }

            return(View(model));
        }
        public void Inserir(MensagemSite objeto)
        {
            try
            {
                _contexto.MensagensSite.Add(objeto);
                _contexto.SaveChanges();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        public ActionResult CreateEdit(LocalInstalacao model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //Create or Edit?
            var li = string.IsNullOrEmpty(model.Tag) ? new LocalInstalacao() : db.Locais.Find(model.Tag);

            //Bind
            li = model;

            //Add new register
            db.Locais.Add(li);

            //Commit
            db.SaveChanges();

            return(RedirectToAction("CreateEdit", 0));
        }
 public void Salvar()
 {
     _contexto.SaveChanges();
 }