public ActionResult DeleteConfirmed(decimal?id) { try { StateActivity__with_Rule2 stateActivity__with_Rule2 = db.StateActivity__with_Rule2.Find(id); db.StateActivity__with_Rule2.Remove(stateActivity__with_Rule2); db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Deleted successfully"); return(RedirectToAction("Index")); } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } return(View()); } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }
public ActionResult Create([Bind(Include = "Id,StateID,ActivityID,Rule2_ID,StartDate,EndDate,Status")] StateActivity__with_Rule2 stateActivity__with_Rule2) { try { ViewBag.ActivityID = new SelectList(db.Activity_Master.OrderBy(m => m.Name), "ID", "Name", stateActivity__with_Rule2.ActivityID); ViewBag.Rule2_ID = new SelectList(db.Rule2_Master.OrderBy(m => m.Name), "Id", "Name", stateActivity__with_Rule2.Rule2_ID); ViewBag.StateID = new SelectList(db.State_Master.OrderBy(m => m.Name), "ID", "Name", stateActivity__with_Rule2.StateID); //if (ModelState.IsValid) //{ if (stateActivity__with_Rule2.StartDate > stateActivity__with_Rule2.EndDate) { ViewBag.message = ToasterMessage.Message(ToastType.info, "End date should be greater then start date"); return(View()); } else { var getName = db.StateActivity__with_Rule2.Where(u => u.StateID == stateActivity__with_Rule2.StateID && u.Rule2_ID == stateActivity__with_Rule2.Rule2_ID && u.StartDate == stateActivity__with_Rule2.StartDate && u.EndDate == stateActivity__with_Rule2.EndDate && u.Status == stateActivity__with_Rule2.Status && u.ActivityID == stateActivity__with_Rule2.ActivityID).ToList(); if (getName.Count > 0) { ViewBag.message = ToasterMessage.Message(ToastType.info, "Record already exist"); return(View()); } else { db.StateActivity__with_Rule2.Add(stateActivity__with_Rule2); db.SaveChanges(); TempData["message"] = ToasterMessage.Message(ToastType.success, "Saved successfully"); return(RedirectToAction("Index")); } } //} } catch (DbEntityValidationException e) { string errorMessage = string.Empty; foreach (DbEntityValidationResult eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (DbValidationError ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); errorMessage = ve.ErrorMessage; ViewBag.message = ViewBag.message + ToasterMessage.Message(ToastType.error, errorMessage); } } } catch (Exception) { ViewBag.message = ToasterMessage.Message(ToastType.error, "Something went wrong"); } return(View()); }