Пример #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));
        }