Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 4
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));
        }