예제 #1
0
        public async Task <IHttpActionResult> RepeatSubCalendarEvent([FromBody] getEventModel repeatSubEventRequestData)
        {
            this.authenticateUser(repeatSubEventRequestData);
            UserAccount retrievedUser = await repeatSubEventRequestData.getUserAccount(db);

            await retrievedUser.Login();

            retrievedUser.getTilerUser().updateTimeZoneTimeSpan(repeatSubEventRequestData.getTimeSpan);
            PostBackData    retValue = new PostBackData("", 1);
            DateTimeOffset  refNow   = repeatSubEventRequestData.getRefNow();
            DB_UserActivity activity = new DB_UserActivity(refNow, UserActivity.ActivityType.Repeat);
            JObject         json     = JObject.FromObject(repeatSubEventRequestData);

            activity.updateMiscelaneousInfo(json.ToString());
            if (retrievedUser.Status)
            {
                string CalendarType = repeatSubEventRequestData.ThirdPartyType.ToLower();

                switch (CalendarType)
                {
                case "google":
                {
                    CustomErrors error = new CustomErrors(CustomErrors.Errors.TilerConfig_Repeat_Third_Party);
                    retValue = new PostBackData(error);
                }
                break;

                case "tiler":
                {
                    HashSet <string> calendarIds = new HashSet <string>()
                    {
                        repeatSubEventRequestData.EventID
                    };
                    Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db);
                    DB_Schedule schedule = new DB_Schedule(retrievedUser, refNow, repeatSubEventRequestData.getCurrentLocation(), retrievalOptions: DataRetrievalSet.scheduleManipulationWithUpdateHistory, calendarIds: calendarIds);
                    schedule.CurrentLocation = repeatSubEventRequestData.getCurrentLocation();
                    var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false);

                    schedule.updateDataSetWithThirdPartyData(thirdPartyData);
                    activity.eventIds.Add(repeatSubEventRequestData.EventID);
                    retrievedUser.ScheduleLogControl.updateUserActivty(activity);
                    schedule.RepeatEvent(repeatSubEventRequestData.EventID, schedule.CurrentLocation);
                    await schedule.WriteFullScheduleToLog().ConfigureAwait(false);

                    retValue = new PostBackData("\"Success\"", 0);
                }
                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));
        }
예제 #2
0
        public async Task <IHttpActionResult> Now([FromBody] NowEventModel nowEvent)
        {
            this.authenticateUser(nowEvent);
            UserAccount retrievedUser = await nowEvent.getUserAccount(db); //new UserAccountDirect(myUser.UserName, myUser.UserID);

            await retrievedUser.Login();

            retrievedUser.getTilerUser().updateTimeZoneTimeSpan(nowEvent.getTimeSpan);
            PostBackData retValue;

            if (retrievedUser.Status)
            {
                HashSet <string> calendarIds = new HashSet <string>()
                {
                    nowEvent.ID
                };
                Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db);
                var retrievalOption = DataRetrievalSet.scheduleManipulation;
                retrievalOption.Add(DataRetrivalOption.TimeLineHistory);
                DB_Schedule schedule = new DB_Schedule(retrievedUser, nowEvent.getRefNow(), nowEvent.getCurrentLocation(), retrievalOptions: retrievalOption, calendarIds: calendarIds);
                schedule.CurrentLocation = nowEvent.getCurrentLocation();
                var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false);

                schedule.updateDataSetWithThirdPartyData(thirdPartyData);
                var ScheduleUpdateMessage = await schedule.SetCalendarEventAsNow(nowEvent.ID).ConfigureAwait(false);

                DB_UserActivity activity = new DB_UserActivity(nowEvent.getRefNow(), UserActivity.ActivityType.SetAsNowCalendarEvent, new List <String>()
                {
                    nowEvent.ID
                });
                JObject json = JObject.FromObject(nowEvent);
                activity.updateMiscelaneousInfo(json.ToString());
                retrievedUser.ScheduleLogControl.updateUserActivty(activity);
                await schedule.persistToDB().ConfigureAwait(false);

                retValue = new PostBackData(ScheduleUpdateMessage.Item1);
            }
            else
            {
                retValue = new PostBackData("", 1);
            }
            await AnalysisController.updateSuggestionAnalysis(retrievedUser.ScheduleLogControl).ConfigureAwait(false);

            TilerFront.SocketHubs.ScheduleChange scheduleChangeSocket = new TilerFront.SocketHubs.ScheduleChange();
            scheduleChangeSocket.triggerRefreshData(retrievedUser.getTilerUser());
            return(Ok(retValue.getPostBack));
        }
예제 #3
0
        public async Task <IHttpActionResult> DeleteCalEvent([FromBody] getEventModel myUser)
        {
            this.authenticateUser(myUser);
            UserAccount retrievedUser = await myUser.getUserAccount(db);// new UserAccount(myUser.UserName, myUser.UserID);

            await retrievedUser.Login();

            retrievedUser.getTilerUser().updateTimeZoneTimeSpan(myUser.getTimeSpan);
            PostBackData retValue;

            if (retrievedUser.Status)
            {
                HashSet <string> calendarIds = new HashSet <string>()
                {
                    myUser.EventID
                };
                Task <Tuple <ThirdPartyControl.CalendarTool, IEnumerable <CalendarEvent> > > thirdPartyDataTask = ScheduleController.updatemyScheduleWithGoogleThirdpartyCalendar(retrievedUser.UserID, db);
                DB_Schedule schedule = new DB_Schedule(retrievedUser, myUser.getRefNow(), myUser.getCurrentLocation(), calendarIds: calendarIds);
                schedule.CurrentLocation = myUser.getCurrentLocation();
                var thirdPartyData = await thirdPartyDataTask.ConfigureAwait(false);

                schedule.updateDataSetWithThirdPartyData(thirdPartyData);
                DB_UserActivity activity = new DB_UserActivity(myUser.getRefNow(), UserActivity.ActivityType.DeleteCalendarEvent, new List <String>()
                {
                    myUser.EventID
                });
                JObject json = JObject.FromObject(myUser);
                activity.updateMiscelaneousInfo(json.ToString());
                retrievedUser.ScheduleLogControl.updateUserActivty(activity);
                CustomErrors messageReturned = await schedule.deleteCalendarEventAndReadjust(myUser.EventID).ConfigureAwait(false);

                await schedule.WriteFullScheduleToLog().ConfigureAwait(false);

                int errorCode = messageReturned?.Code ?? 0;
                retValue = new PostBackData(messageReturned, errorCode);
            }
            else
            {
                retValue = new PostBackData("", 1);
            }

            TilerFront.SocketHubs.ScheduleChange scheduleChangeSocket = new TilerFront.SocketHubs.ScheduleChange();
            await AnalysisController.updateSuggestionAnalysis(retrievedUser.ScheduleLogControl).ConfigureAwait(false);

            scheduleChangeSocket.triggerRefreshData(retrievedUser.getTilerUser());
            return(Ok(retValue.getPostBack));
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }