public virtual JsonResult Event_Destroy([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel) { if (ModelState.IsValid) { //int fromCalendarId = 0; string fromCalendar = string.Empty; int fromCalendarId = (int)eventViewModel.CalenderUser; using (var OrderMangtDB = new OrderMgntEntities()) { //fromCalendarId = (int)OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId; fromCalendar = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == fromCalendarId).Name; } try { if (!string.IsNullOrEmpty(eventViewModel.EventId)) { string eventid = eventViewModel.EventId; var objGoogleCal = new GoogleServiceMethodCalls(); objGoogleCal.DeleteEvent(eventid, fromCalendar); using (var OrderMangtDB = new OrderMgntEntities()) { var Events = (from oEvents in OrderMangtDB.Events where oEvents.EventId == eventid && oEvents.CalendarId == fromCalendarId select oEvents).ToList(); foreach (var Event in Events) { Event.Status = "cancelled"; } OrderMangtDB.SaveChanges(); int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(eventViewModel.EventId, eventViewModel.Title, "Cancelled Event", LoggedInUserId, fromCalendar, fromCalendar); } // Check if more than one rec is exist // var AllEventByCalendarIdAndEventId = _scheduler.GetAllEventByCalendarIdAndEventId(eventid, CalendarId); // DeleteEvent(eventViewModel.EventId, fromCalendar, fromCalendarId); } else if (!string.IsNullOrEmpty(eventViewModel.GoogleEventid)) { DeleteEvent(eventViewModel.GoogleEventid, fromCalendar, fromCalendarId); int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(eventViewModel.GoogleEventid, eventViewModel.Title, "Cancelled Event", LoggedInUserId, fromCalendar, fromCalendar); } } catch (Exception ex) { string msg = ex.Message; Logger(msg); } } return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState)); }
private void DeleteEvent(string eventid, string calendar, int CalendarId) { if (!string.IsNullOrEmpty(eventid)) { var objGoogleCal = new GoogleServiceMethodCalls(); objGoogleCal.DeleteEvent(eventid, calendar); // Check if more than one rec is exist // var AllEventByCalendarIdAndEventId = _scheduler.GetAllEventByCalendarIdAndEventId(eventid, CalendarId); // if (AllEventByCalendarIdAndEventId.Count > 1) // { using (var OrderMangtDB = new OrderMgntEntities()) { var Events = (from oEvents in OrderMangtDB.Events where oEvents.EventId == eventid && oEvents.CalendarId == CalendarId select oEvents).ToList(); foreach (var Event in Events) { Event.Status = "cancelled"; } OrderMangtDB.SaveChanges(); } // } //else //{ // Event objevent1 = _scheduler.GetEventByCalendarIdAndEventId(eventid, CalendarId); // _scheduler.DeleteEvent(objevent1); //} //using (var OrderMangtDB = new OrderMgntEntities()) //{ // Event objevent = OrderMangtDB.Events.Single(e => e.EventId == eventid && e.CalendarId == CalendarId); // objevent.Status = "cancelled"; // OrderMangtDB.SaveChanges(); //} } }