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)); }
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> SubeventEdit([FromBody] EditSubEventWhatIfModel SubEventEdit) { UserAccount retrievedUser = await SubEventEdit.getUserAccount(db); await retrievedUser.Login(); retrievedUser.getTilerUser().updateTimeZoneTimeSpan(SubEventEdit.getTimeSpan); PostBackData returnPostBack; if (retrievedUser.Status) { int SplitCount = (int)SubEventEdit.Split; long StartLong = Convert.ToInt64(SubEventEdit.Start); long EndLong = Convert.ToInt64(SubEventEdit.End); long LongBegin = Convert.ToInt64(SubEventEdit.CalStart); long LongDeadline = Convert.ToInt64(SubEventEdit.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; } DateTimeOffset now = SubEventEdit.getRefNow(); DB_Schedule schedule; Tuple <Health, Health> evaluation; string CalendarType = SubEventEdit.ThirdPartyType.ToLower(); switch (CalendarType) { case "google": { Models.ThirdPartyCalendarAuthenticationModel AllIndexedThirdParty = await ScheduleController.getThirdPartyAuthentication(retrievedUser.UserID, SubEventEdit.ThirdPartyUserID, "Google", db); GoogleTilerEventControl googleControl = new GoogleTilerEventControl(AllIndexedThirdParty, db); await googleControl.updateSubEvent(SubEventEdit).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(now, UserActivity.ActivityType.ThirdPartyUpdate); retrievedUser.ScheduleLogControl.updateUserActivty(activity); Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db); schedule = new DB_Schedule(retrievedUser, now, SubEventEdit.getCurrentLocation()); var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false); schedule.updateDataSetWithThirdPartyData(thirdPartyData); evaluation = await schedule.TimeStone.EventUpdate().ConfigureAwait(false); } break; case "tiler": { HashSet <string> calendarIds = new HashSet <string>() { SubEventEdit.EventID }; Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db); var retrievalOption = DataRetrievalSet.scheduleManipulation; retrievalOption.Add(DataRetrivalOption.TimeLineHistory); schedule = new DB_Schedule(retrievedUser, now, SubEventEdit.getCurrentLocation(), calendarIds: calendarIds, retrievalOptions: retrievalOption); var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false); schedule.updateDataSetWithThirdPartyData(thirdPartyData); schedule.CurrentLocation = SubEventEdit.getCurrentLocation(); evaluation = await schedule.TimeStone.EventUpdate( newStart, newEnd, Begin, Deadline, SplitCount, SubEventEdit.EventID ).ConfigureAwait(false); } break; default: CustomErrors error = new CustomErrors(CustomErrors.Errors.Preview_Calendar_Type_Not_Supported); returnPostBack = new PostBackData(error); return(Ok(returnPostBack.getPostBack)); } JObject before = evaluation.Item1.ToJson(); JObject after = evaluation.Item2.ToJson(); HealthComparison healthComparison = new HealthComparison(evaluation.Item1, evaluation.Item2); var delta = healthComparison.delta(); JObject deltaJson = new JObject(); deltaJson.Add("conflictDeltaCount", delta.Item1); deltaJson.Add("tardyDeltaCount", delta.Item2); JObject resultData = new JObject(); resultData.Add("before", before); resultData.Add("after", after); resultData.Add("delta", deltaJson); returnPostBack = new PostBackData(resultData, 0); return(Ok(returnPostBack.getPostBack)); } else { returnPostBack = new PostBackData("", 1); } return(Ok(returnPostBack.getPostBack)); }