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(); //} } }
public virtual JsonResult print([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel) { try { string returnedEventId = string.Empty; if (string.IsNullOrEmpty(eventViewModel.RecurrenceException)) { if (ModelState.IsValid) { var tasksEventCalendar = _scheduler.GetAllEventByEventID(eventViewModel.EventId); var CalendarsByRowId = _scheduler.GetCalendarsByRowId(eventViewModel.CalendarId); // var eventCalendar = OrderMangtDB.Events.First(x => x.EventId == eventViewModel.EventId).CalendarId; var eventCalendar = tasksEventCalendar.First(x => x.EventId == eventViewModel.EventId).CalendarId; var entity = tasksEventCalendar.FirstOrDefault(m => m.EventId == eventViewModel.EventId); // Create a new Task entity and set its properties from the posted TaskViewModel if (!string.IsNullOrEmpty(eventViewModel.EventId)) { entity.EventId = eventViewModel.EventId; } entity.Title = eventViewModel.Title; //Specify the DateTimeKind to be UTC entity.StartDate = eventViewModel.Start; entity.EndDate = eventViewModel.End; entity.Description = eventViewModel.Description; entity.Recurrence = eventViewModel.RecurrenceRule; entity.RecurrenceID = eventViewModel.RecurrenceID; entity.CalendarId = eventViewModel.CalenderUser != null ? eventViewModel.CalenderUser : entity.CalendarId; entity.Organizer = eventViewModel.Organizer; entity.Kind = "calendar#event"; entity.Location = eventViewModel.Location; entity.Updated = DateTime.Today; entity.Sequence = eventViewModel.Sequence == 0 ? entity.Sequence + 1 : 0; // entity.Sequence = eventViewModel.Sequence; entity.IsAllDay = eventViewModel.IsAllDay; GoogleServiceMethodCalls objGoogleCal = new GoogleServiceMethodCalls(); var CalendarsUser = _scheduler.GetCalendarsByRowId(eventViewModel.CalenderUser); var calendars = CalendarsUser.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser); string DestinationCalName = CalendarsUser.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser).Name.ToString(); if (eventCalendar != eventViewModel.CalenderUser) { // var fromCalendarId = OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId; var fromCalendar = CalendarsByRowId.SingleOrDefault(m => m.Row_Id == eventViewModel.CalendarId); string frmCalName = fromCalendar.Name.ToString(); if (entity.StartDate != null && entity.EndDate != null) Logger("MoveEvent within Update block Called" + " || " + entity.Title); int OldEventRowId = Convert.ToInt32(_scheduler.GetEventRowId(eventViewModel.EventId).FirstOrDefault().EventRow_id); returnedEventId = objGoogleCal.MoveEvent(entity.StartDate.Value, entity.EndDate.Value, string.Empty, string.Empty, entity.Location, entity.Title, entity.EventId, DestinationCalName, frmCalName, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, entity.ColorId ?? string.Empty); eventViewModel.EventId = returnedEventId; int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(returnedEventId, entity.Title, "Move Event", LoggedInUserId, frmCalName, DestinationCalName); _scheduler.UpdateJobEvents(returnedEventId, DestinationCalName, frmCalName, OldEventRowId);///UpdateJobEvents /// Logger("UpdateJobEvents Called - " + "eventId: " + returnedEventId + " Source calendar Name : " + frmCalName + " Destination calendar Name : " + DestinationCalName); /// /// LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(returnedEventId, entity.Title, "Move Event", LoggedInUserId, frmCalName, DestinationCalName); ThrowCustomExc(returnedEventId); Logger("MoveEvent end within Update block Called"); } else { string colorid = string.Empty; if (eventViewModel.EventColorid.HasValue) { if (eventViewModel.EventColorid.Value <= 11) colorid = eventViewModel.EventColorid.ToString(); } else { if (eventViewModel.CalenderUser != null) { // colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value); colorid = string.Empty; } } Logger("UpdateEvent called within Update block " + " || " + entity.Title); returnedEventId = objGoogleCal.UpdateEvent((DateTime)entity.StartDate, (DateTime)entity.EndDate, string.Empty, entity.Organizer, entity.Location, entity.Title, entity.EventId, calendars.Name, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, colorid ?? entity.ColorId); int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(returnedEventId, entity.Title, "Update Event", LoggedInUserId, calendars.Name, calendars.Name); ThrowCustomExc(returnedEventId); eventViewModel.EventId = returnedEventId; Logger("UpdateEvent end within Update block "); } } } // Return the updated task. Also return any validation errors. return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState)); } catch (Exception ex) { #region For Error string Error = ErrorMsg; if (!string.IsNullOrEmpty(ErrorMsg)) { switch (Error) { case "CustomError400": return Json(new DataSourceResult { // Errors = "You cannot change the organizer of an instance." Errors = "CustomError400" }); case "CustomError401": return Json(new DataSourceResult { //Errors = "You cannot turn an instance of a recurring event into a recurring event itself." Errors = "CustomError401" }); case "Null_Event": return Json(new DataSourceResult { Errors = "Null_Event" }); default: return Json(new DataSourceResult { Errors = "" }); } } else { return Json(new DataSourceResult { Errors = "" }); } #endregion For Error } }
public virtual JsonResult Event_Create([DataSourceRequest] DataSourceRequest request, CalEventViewModel eventViewModel, List<int> userIds) { try { if (ModelState.IsValid) { using (var OrderMangtDB = new OrderMgntEntities()) { var entity = new Event { Title = eventViewModel.Title, //StartDate = DateTime.SpecifyKind(eventViewModel.Start, DateTimeKind.Local), //EndDate = DateTime.SpecifyKind(eventViewModel.End, DateTimeKind.Local), StartDate = eventViewModel.Start,//StartDateParam, EndDate = eventViewModel.End, Description = eventViewModel.Description, Recurrence = eventViewModel.RecurrenceRule, RecurrenceID = eventViewModel.RecurrenceID, Kind = "calendar#event", IsAllDay = eventViewModel.IsAllDay, CalendarId = eventViewModel.CalenderUser, Organizer = eventViewModel.Organizer, Creator = eventViewModel.Creator, Updated = DateTime.Today, Location = eventViewModel.Location, ColorId = eventViewModel.ColorId }; var objGoogleCal = new GoogleServiceMethodCalls(); string returnedEventid = string.Empty; int fromCalId; string calName = string.Empty; int orgId; string StagingCalendar = string.Empty; if (eventViewModel.Row_Id != 0) { fromCalId = (int)OrderMangtDB.Events.First(x => x.Row_Id == eventViewModel.Row_Id).CalendarId; calName = OrderMangtDB.Calendars.FirstOrDefault(c => c.Row_Id == fromCalId).Name; orgId = (int)UserManager.Current().OrgId; StagingCalendar = OrderMangtDB.Calendars.FirstOrDefault(x => (x.Org_Id != null && x.Org_Id == orgId) && (x.StagingCalendar != null && x.StagingCalendar == true)).Name; } if (eventViewModel.Isdrag && calName != StagingCalendar && eventViewModel.Row_Id != 0) { string creator = string.Empty; string organizer = string.Empty; string eventId = eventViewModel.GoogleEventid; int eventRowId = eventViewModel.Row_Id; string destinationCalendar = eventViewModel.CalenderUser.ToString(); var calendars = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser); var fromCalendarId = OrderMangtDB.Events.First(m => m.Row_Id == eventRowId).CalendarId; var fromCalendar = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == fromCalendarId); if (calendars != null) { if (entity.StartDate != null && entity.EndDate != null) { Logger("MoveEvent called within Create block Called" + " || " + entity.Title); int OldEventRowId = Convert.ToInt32(_scheduler.GetEventRowId(eventId).FirstOrDefault().EventRow_id); returnedEventid = objGoogleCal.MoveEvent(entity.StartDate.Value, entity.EndDate.Value, creator, organizer, entity.Location, entity.Title, eventId, calendars.Name, fromCalendar.Name, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, entity.ColorId ?? string.Empty); eventViewModel.EventId = returnedEventid; int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(returnedEventid, entity.Title, "MoveEvent", LoggedInUserId, fromCalendar.Name, calendars.Name); _scheduler.UpdateJobEvents(returnedEventid, calendars.Name, fromCalendar.Name, OldEventRowId);///UpdateJobEvents Logger("UpdateJobEvents Called - " + "eventId: " + returnedEventid + " Source calendar Name : " + fromCalendar.Name + " Destination calendar Name : " + calendars.Name); /// LoggedInUserId= (int)UserManager.Current().Row_Id; DBLogger(returnedEventid, entity.Title, "MoveEvent", LoggedInUserId, fromCalendar.Name, calendars.Name); ThrowCustomExc(returnedEventid); Logger("MoveEvent end within Create block Called"); } // objGoogleCal.UpdateEvent(entity.StartDate.Value, entity.EndDate.Value, creator, organizer, entity.Location, entity.Title, eventId, calendars.Name); } } else if (!string.IsNullOrEmpty(eventViewModel.RecurrenceID)) { var evnt = OrderMangtDB.Events.First(x => x.EventId == eventViewModel.RecurrenceID && x.Status != "Cancelled"); var cal = OrderMangtDB.Calendars.First(x => x.Row_Id == evnt.CalendarId).Name; string colorid = string.Empty; if (eventViewModel.EventColorid.HasValue) { if (eventViewModel.EventColorid.Value <= 11) colorid = eventViewModel.EventColorid.ToString(); } else { if (eventViewModel.CalenderUser != null) { // colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value); colorid = string.Empty; } } entity.EventId = eventViewModel.RecurrenceID; // entity.Sequence = 0; int Sequenceid = (int)OrderMangtDB.Events.First(x => x.EventId == eventViewModel.RecurrenceID).Sequence; Sequenceid++; entity.Sequence = Sequenceid; // != 0 ? Sequenceid: Sequenceid + 1; Logger("UpdateEventInstance called within Create block Called" + " || " + entity.Title); //var startDate = (DateTime)entity.StartDate; // if (startDate.TimeOfDay.Minutes < 15 && startDate.TimeOfDay.Minutes > 0) // { // startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startDate.Hour, 00, 00); // } var returnedEventId = objGoogleCal.UpdateEventInstance((DateTime)entity.StartDate, (DateTime)entity.EndDate, string.Empty, entity.Organizer, entity.Location, entity.Title, entity.EventId, cal, (int)entity.Sequence, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false, colorid ?? entity.ColorId); int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(returnedEventId, entity.Title, "Update Event", LoggedInUserId, cal, cal); // string retUpdateEventId = returnedEventId; ThrowCustomExc(returnedEventId); Logger("UpdateEventInstance end within Create block Called"); } else { string colorid = string.Empty; if (eventViewModel.EventColorid.HasValue) { if (eventViewModel.EventColorid.Value < 12) // we only need to pass top 11 clolor while create update { colorid = eventViewModel.EventColorid.ToString(); } } else { if (!string.IsNullOrEmpty(eventViewModel.Color)) { // colorid = eventViewModel.ColorId, colorid = OrderMangtDB.ColorMasters.First(x => x.Color == eventViewModel.Color).Row_Id.ToString(); } else { colorid = string.Empty; } //if (eventViewModel.CalenderUser != null) //{ // colorid = GetUsercalenderColor(eventViewModel.CalenderUser.Value); //} //colorid = string.Empty; } var calendars = OrderMangtDB.Calendars.SingleOrDefault(m => m.Row_Id == eventViewModel.CalenderUser); Logger("UpdateEventInstance end within Create block Called" + " || " + entity.Title); returnedEventid = objGoogleCal.CreateEvent(entity.Title, entity.Location, string.Empty, entity.StartDate.Value, entity.EndDate.Value, string.Empty, entity.Description, string.Empty, string.Empty, colorid, calendars.Name, entity.Description ?? string.Empty, entity.Recurrence ?? string.Empty, entity.IsAllDay ?? false); string strreturnedEventid = returnedEventid; string[] parts = strreturnedEventid.Split(','); string EventidfrmGoogle = string.Empty; string seqId = string.Empty; if ((parts[0] != null && parts[0].Length > 0)) { EventidfrmGoogle = (parts[0].ToString()); seqId = (parts[1].ToString()); } int LoggedInUserId = (int)UserManager.Current().Row_Id; DBLogger(EventidfrmGoogle, entity.Title, "Create Event", LoggedInUserId, calendars.Name, calendars.Name); Logger("CreateEvent end within Create block Called"); if (returnedEventid != string.Empty) { var retValues = returnedEventid.Split(','); eventViewModel.EventId = retValues[0]; eventViewModel.Sequence = Convert.ToInt32(retValues[1]); ThrowCustomExc(retValues[0]); } } } } } catch (Exception ex) { #region For Error string Error = ErrorMsg; if (!string.IsNullOrEmpty(ErrorMsg)) { switch (Error) { case "CustomError400": return Json(new DataSourceResult { // Errors = "You cannot change the organizer of an instance." Errors = "CustomError400" }); case "CustomError401": return Json(new DataSourceResult { //Errors = "You cannot turn an instance of a recurring event into a recurring event itself." Errors = "CustomError401" }); case "Null_Event": return Json(new DataSourceResult { Errors = "Null_Event" }); //default: // Logger(ex.InnerException.Message); // return Json(new DataSourceResult // { // Errors = string.Empty // }); } } else { return Json(new DataSourceResult { Errors = "" }); } #endregion } // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors. //List<int> userid = new List<int> { }; //Event_Read(request, "", DateTime.Now, DateTime.Now); return Json(new[] { eventViewModel }.ToDataSourceResult(request, ModelState)); }
public ActionResult DeleteRecurrence(string eventid, int calendarId, string calenderUser, DateTime end, DateTime start) { string calenderName = string.Empty; string rtneventid = string.Empty; string exceptionfrmDB = string.Empty; string strNewDate = string.Empty; var objGoogleCal = new GoogleServiceMethodCalls(); using (var OrderMangtDB = new OrderMgntEntities()) { calenderName = OrderMangtDB.Calendars.FirstOrDefault(m => m.Row_Id == calendarId).Name; if (!string.IsNullOrEmpty(calenderName)) { rtneventid = objGoogleCal.DeleteEventInstance(eventid, calenderName, start); if (!rtneventid.Equals("Instance not available")) { string Currexception = rtneventid.Split('_').Last(); //var datepart = Currexception.Split('T').First(); //var newDate = DateTime.ParseExact(datepart, "yyyyMMdd", CultureInfo.InvariantCulture).AddDays(1); //strNewDate = newDate.Year.ToString() + newDate.Month.ToString() + newDate.Day.ToString(); //Currexception = Currexception.Replace(datepart, strNewDate); string streventid = eventid; var exceptionEntry = OrderMangtDB.EventExceptions.FirstOrDefault(c => c.EventId == streventid); if (exceptionEntry != null) { exceptionfrmDB = exceptionEntry.Exception; } if (exceptionfrmDB == string.Empty) { if (!exceptionfrmDB.Contains(Currexception)) exceptionfrmDB = Currexception; } else { exceptionfrmDB = exceptionfrmDB + ";" + Currexception; } if (exceptionEntry == null) { var EventException = new EventException { EventId = eventid, Exception = exceptionfrmDB }; OrderMangtDB.EventExceptions.Add(EventException); } else { exceptionEntry.Exception = exceptionfrmDB; } OrderMangtDB.SaveChanges(); } else { using (var OrderMangtDB2 = new OrderMgntEntities()) { var Events = (from oEvents in OrderMangtDB2.Events where oEvents.EventId == eventid && oEvents.CalendarId == calendarId select oEvents).ToList(); foreach (var Event in Events) { Event.Status = "cancelled"; } OrderMangtDB2.SaveChanges(); } } } } return Content(rtneventid); }