public ActionResult AddOrUpdateEvents(EventDTO dtoEvent) { try { using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities()) { DateTime invitationDate = DateTime.ParseExact(dtoEvent.Date, "MM/dd/yyyy h:mm tt", null); //Following line is used to get logged in userid string usrkey = User.Identity.GetUserId(); if (dtoEvent.id != 0) { var Data = dbcontext.mblist_events_detail.Find(dtoEvent.id); if (Data != null) { Data.event_detail_category_key = dtoEvent.Category; Data.event_detail_type_key = dtoEvent.EventFor; Data.event_detail_title = dtoEvent.Title; Data.event_detail_address = dtoEvent.Address; Data.event_detail_discription = dtoEvent.Comment; Data.event_detail_date = invitationDate; Data.event_detail_user_key = usrkey; dbcontext.SaveChanges(); return(Json(new { key = true, value = "event updated successfully", eventKey = Data.event_detail_key }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { key = false, value = "event event not found" }, JsonRequestBehavior.AllowGet)); } } else { mblist_events_detail evn = new mblist_events_detail() { event_detail_category_key = dtoEvent.Category, event_detail_type_key = dtoEvent.EventFor, event_detail_title = dtoEvent.Title, event_detail_address = dtoEvent.Address, event_detail_date = invitationDate, event_detail_discription = dtoEvent.Comment, event_detail_user_key = usrkey, event_subject_color = "brown", event_font_color = "#000", event_subject = "You are invited for an event" }; dbcontext.mblist_events_detail.Add(evn); dbcontext.SaveChanges(); return(Json(new { key = true, value = "event added successfully", eventKey = evn.event_detail_key }, JsonRequestBehavior.AllowGet)); } }; } catch (Exception ex) { return(Json(new { key = false, value = "Unable to save the event" }, JsonRequestBehavior.AllowGet));; } }
public ActionResult AddSubevent(EventDTO sbevntdto) { try { using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities()) { string usrkey = System.Web.HttpContext.Current.User.Identity.GetUserId(); if (sbevntdto.id != 0) { DateTime date = DateTime.ParseExact(sbevntdto.Date, "MM/dd/yyyy h:mm tt", null); mblist_events_detail sbven = new mblist_events_detail() { event_detail_user_key = usrkey, event_parent = sbevntdto.id, event_detail_category_key = sbevntdto.Category, event_detail_type_key = sbevntdto.EventFor, event_detail_title = sbevntdto.Title, event_detail_address = sbevntdto.Address, event_detail_date = date, event_detail_discription = sbevntdto.Comment }; dbcontext.mblist_events_detail.Add(sbven); dbcontext.SaveChanges(); return(Json(new { key = true, value = "Subevent added successfully", sbevntkey = sbven.event_detail_key }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { key = false, value = "Please create an event" }, JsonRequestBehavior.AllowGet)); } }; } catch (Exception ex) { return(Json(new { key = false, value = "Unable to process your request. Please contact your admin" }, JsonRequestBehavior.AllowGet)); } }