public async Task <IHttpActionResult> UpdateCalEvent([FromBody] EditSubCalEventModel editSubEventRequest) { this.authenticateUser(editSubEventRequest); UserAccount retrievedUser = await editSubEventRequest.getUserAccount(db); await retrievedUser.Login(); retrievedUser.getTilerUser().updateTimeZoneTimeSpan(editSubEventRequest.getTimeSpan); PostBackData retValue = new PostBackData("", 1); if (retrievedUser.Status) { string CalendarType = editSubEventRequest.ThirdPartyType.ToLower(); switch (CalendarType) { case "google": { DateTimeOffset myNow = editSubEventRequest.getRefNow(); var retrievalOption = DataRetrievalSet.scheduleManipulation; retrievalOption.Add(DataRetrivalOption.TimeLineHistory); DB_Schedule NewSchedule = new DB_Schedule(retrievedUser, myNow, editSubEventRequest.getCurrentLocation(), retrievalOption); NewSchedule.CurrentLocation = editSubEventRequest.getCurrentLocation(); Models.ThirdPartyCalendarAuthenticationModel AllIndexedThirdParty = await ScheduleController.getThirdPartyAuthentication(retrievedUser.UserID, editSubEventRequest.ThirdPartyUserID, "Google", db); GoogleTilerEventControl googleControl = new GoogleTilerEventControl(AllIndexedThirdParty, db); await googleControl.updateSubEvent(editSubEventRequest).ConfigureAwait(false); Dictionary <string, CalendarEvent> AllCalendarEvents = (await googleControl.getCalendarEvents(null, true).ConfigureAwait(false)).ToDictionary(obj => obj.getId, obj => obj); GoogleThirdPartyControl googleEvents = new GoogleThirdPartyControl(AllCalendarEvents, AllIndexedThirdParty.getTilerUser()); DB_UserActivity activity = new DB_UserActivity(myNow, UserActivity.ActivityType.ThirdPartyUpdate); retrievedUser.ScheduleLogControl.updateUserActivty(activity); await NewSchedule.updateDataSetWithThirdPartyDataAndTriggerNewAddition(new Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> >(ThirdPartyControl.CalendarTool.google, new List <CalendarEvent> { googleEvents.getThirdpartyCalendarEvent() })).ConfigureAwait(false); retValue = new PostBackData("\"Success\"", 0); } break; case "tiler": { DateTimeOffset myNow = editSubEventRequest.getRefNow(); myNow = editSubEventRequest.getRefNow(); HashSet <string> calendarIds = new HashSet <string>() { editSubEventRequest.EventID }; Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db); DB_Schedule schedule = new DB_Schedule(retrievedUser, myNow, editSubEventRequest.getCurrentLocation(), retrievalOptions: DataRetrievalSet.scheduleManipulationWithUpdateHistory, calendarIds: calendarIds); schedule.CurrentLocation = editSubEventRequest.getCurrentLocation(); var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false); schedule.updateDataSetWithThirdPartyData(thirdPartyData); long StartLong = Convert.ToInt64(editSubEventRequest.Start); long EndLong = Convert.ToInt64(editSubEventRequest.End); long LongBegin = Convert.ToInt64(editSubEventRequest.CalStart); long LongDeadline = Convert.ToInt64(editSubEventRequest.CalEnd); DateTimeOffset newStart = TilerElementExtension.JSStartTime.AddMilliseconds(StartLong); DateTimeOffset newEnd = TilerElementExtension.JSStartTime.AddMilliseconds(EndLong); DateTimeOffset Begin = TilerElementExtension.JSStartTime.AddMilliseconds(LongBegin); if (LongBegin == 0) { Begin = Utility.BeginningOfTime; } DateTimeOffset Deadline = TilerElementExtension.JSStartTime.AddMilliseconds(LongDeadline); if (LongDeadline == 0) { Deadline = Utility.BeginningOfTime; } int SplitCount = (int)editSubEventRequest.Split; if (SplitCount >= 1) { SubCalendarEvent subEventedited = schedule.getSubCalendarEvent(editSubEventRequest.EventID); Tuple <CustomErrors, Dictionary <string, CalendarEvent> > ScheduleUpdateMessage = await schedule.BundleChangeUpdate(editSubEventRequest.EventID, new EventName(retrievedUser.getTilerUser(), subEventedited, editSubEventRequest.EventName), newStart, newEnd, Begin, Deadline, SplitCount, editSubEventRequest.EscapedNotes).ConfigureAwait(false); DB_UserActivity activity = new DB_UserActivity(myNow, UserActivity.ActivityType.InternalUpdate, new List <String>() { editSubEventRequest.EventID }); retrievedUser.ScheduleLogControl.updateUserActivty(activity); await schedule.persistToDB().ConfigureAwait(false); //EventID eventId = new EventID(myUser.EventID); //CalendarEvent calendarEvent = schedule.getCalendarEvent(eventId); //SubCalendarEvent subEvent = calendarEvent.ActiveSubEvents.FirstOrDefault(); //SubCalEvent subCalEvent = subEvent.ToSubCalEvent(calendarEvent); //JObject retSubEvent = new JObject(); //retSubEvent.Add("subEvent", JObject.FromObject(subCalEvent)); //retValue = new PostBackData(retSubEvent, 0); retValue = new PostBackData(); } else { CustomErrors error = new CustomErrors(CustomErrors.Errors.TilerConfig_Zero_SplitCount); retValue = new PostBackData(error); } } break; default: break; } } await AnalysisController.updateSuggestionAnalysis(retrievedUser.ScheduleLogControl).ConfigureAwait(false); TilerFront.SocketHubs.ScheduleChange scheduleChangeSocket = new TilerFront.SocketHubs.ScheduleChange(); scheduleChangeSocket.triggerRefreshData(retrievedUser.getTilerUser()); return(Ok(retValue.getPostBack)); }
public async Task <IHttpActionResult> UpdateCalEvent([FromBody] EditCalEventModel myUser) { this.authenticateUser(myUser); UserAccount retrievedUser = await myUser.getUserAccount(db); //new UserAccountDirect(myUser.UserName, myUser.UserID); await retrievedUser.Login(); retrievedUser.getTilerUser().updateTimeZoneTimeSpan(myUser.getTimeSpan); PostBackData retValue = new PostBackData("", 1); if (retrievedUser.Status) { string CalendarType = myUser.ThirdPartyType.ToLower(); switch (CalendarType) { case "google": { Models.ThirdPartyCalendarAuthenticationModel AllIndexedThirdParty = await ScheduleController.getThirdPartyAuthentication(retrievedUser.UserID, myUser.ThirdPartyUserID, "Google", db); GoogleTilerEventControl googleControl = new GoogleTilerEventControl(AllIndexedThirdParty, db); await googleControl.updateSubEvent(myUser).ConfigureAwait(false); Dictionary <string, CalendarEvent> AllCalendarEvents = (await googleControl.getCalendarEvents(null, true).ConfigureAwait(false)).ToDictionary(obj => obj.getId, obj => obj); GoogleThirdPartyControl googleEvents = new GoogleThirdPartyControl(AllCalendarEvents, AllIndexedThirdParty.getTilerUser()); DB_Schedule NewSchedule = new DB_Schedule(retrievedUser, myUser.getRefNow(), myUser.getCurrentLocation(), retrievalOptions: DataRetrievalSet.scheduleManipulationWithUpdateHistory); NewSchedule.CurrentLocation = myUser.getCurrentLocation(); await NewSchedule.updateDataSetWithThirdPartyDataAndTriggerNewAddition(new Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> >(ThirdPartyControl.CalendarTool.google, new List <CalendarEvent> { googleEvents.getThirdpartyCalendarEvent() })).ConfigureAwait(false); retValue = new PostBackData("\"Success\"", 0); } break; case "tiler": { HashSet <string> calendarIds = new HashSet <string>() { myUser.EventID }; DB_Schedule NewSchedule = new DB_Schedule(retrievedUser, myUser.getRefNow(), myUser.getCurrentLocation(), retrievalOptions: DataRetrievalSet.scheduleManipulationWithUpdateHistory, calendarIds: calendarIds); NewSchedule.CurrentLocation = myUser.getCurrentLocation(); DateTimeOffset newStart = TilerElementExtension.JSStartTime.AddMilliseconds(myUser.Start); newStart = newStart.Add(myUser.getTimeSpan); DateTimeOffset newEnd = TilerElementExtension.JSStartTime.AddMilliseconds(myUser.End); newEnd = newEnd.Add(myUser.getTimeSpan); int SplitCount = (int)myUser.Split; TimeSpan SpanPerSplit = TimeSpan.FromMilliseconds(myUser.Duration); CalendarEvent calEvent = NewSchedule.getCalendarEvent(myUser.EventID); Tuple <CustomErrors, Dictionary <string, CalendarEvent> > ScheduleUpdateMessage = await NewSchedule.BundleChangeUpdate(myUser.EventID, new EventName(retrievedUser.getTilerUser(), calEvent, myUser.EventName), newStart, newEnd, SplitCount, myUser.EscapedNotes).ConfigureAwait(false); DB_UserActivity activity = new DB_UserActivity(myUser.getRefNow(), UserActivity.ActivityType.InternalUpdateCalendarEvent, new List <String>() { myUser.EventID }); JObject json = JObject.FromObject(myUser); activity.updateMiscelaneousInfo(json.ToString()); retrievedUser.ScheduleLogControl.updateUserActivty(activity); await NewSchedule.persistToDB().ConfigureAwait(false); retValue = new PostBackData(ScheduleUpdateMessage.Item1); } break; default: break; } } await AnalysisController.updateSuggestionAnalysis(retrievedUser.ScheduleLogControl).ConfigureAwait(false); TilerFront.SocketHubs.ScheduleChange scheduleChangeSocket = new TilerFront.SocketHubs.ScheduleChange(); scheduleChangeSocket.triggerRefreshData(retrievedUser.getTilerUser()); return(Ok(retValue.getPostBack)); }