public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { IntersectedEvents intersection = null; intersection = controllerContext.HttpContext.Session[sessionKey] as IntersectedEvents; if(intersection == null) { intersection = new IntersectedEvents { IsEmpty = true }; } return intersection; }
public ActionResult Intersection(IntersectionViewModel model, IntersectedEvents sessionModel) { if (!sessionModel.IsEmpty) { try { var newEvent = sessionModel.NewEvent; if (model.Id != -1 && model.Id == newEvent.Id) { _db.Update(newEvent); } else if (model.Id == -1 && newEvent.Id == -1 && model.Name.Equals(newEvent.Name, StringComparison.Ordinal)) { _db.Add(newEvent); } return RedirectToAction("GetAll"); } catch { ModelState.AddModelError("", "Can't save changes."); return Json(new { status = "error", errors = GetErrors(ModelState) }, JsonRequestBehavior.DenyGet); } } ModelState.AddModelError("", "Oops, something went wrong"); return Json(new { status = "error", errors = GetErrors(ModelState) }, JsonRequestBehavior.DenyGet); }
public JsonResult Intersection(IntersectedEvents model) { var sb = new StringBuilder("The event that you creates is intersects with: "); if (model.OldEvents.Count() <= 5) { foreach (var oldEvent in model.OldEvents) { sb.Append(oldEvent.Name + ", "); } sb.Length = sb.Length - 2; sb.Append("."); } else { foreach (var oldEvent in model.OldEvents.Take(5)) { sb.Append(oldEvent.Name + ", "); } sb.Length = sb.Length - 2; sb.Append(" and others."); } return Json(new { status = "intersected", id = model.NewEvent.Id, name = model.NewEvent.Name, message = sb.ToString() }, JsonRequestBehavior.AllowGet); }