Beispiel #1
0
        public IActionResult CheckToken([FromBody] TokenDTO token)
        {
            if (token == null)
            {
                return(NotFound());
            }

            SecurityLinkToken _token = contextUsers.SecurityLinkTokens.Find(token.token);

            if (_token == null)
            {
                return(NotFound());
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <string> ValidateAsync([FromBody] TokenDTO token)
        {
            if (token == null)
            {
                return("NotFound");
            }

            Widget wgt = context.Widgets.Find(Guid.Parse(token.token));

            if (wgt == null)
            {
                return("NotFound");
            }

            if (wgt.Status != "Active")
            {
                return("NotActive");
            }

            if (string.IsNullOrWhiteSpace(wgt.AuthKey) || string.IsNullOrWhiteSpace(wgt.Extension))
            {
                return("NotActive");
            }

            if (String.IsNullOrEmpty(wgt.subscriptionId))
            {
                return("NoSubscription");
            }

            if (await IsWidgetOutofCallAsync(wgt, context))
            {
                return("OutofCall");
            }

            if (IsWidgetOutofSubscription(wgt, context))
            {
                return("SubscriptionExpired");
            }

            return("OK");
        }
Beispiel #3
0
        public async Task <IActionResult> CheckActivationToken([FromBody] TokenDTO token)
        {
            if (token == null)
            {
                return(NotFound());
            }

            SecurityLinkToken _token = contextUsers.SecurityLinkTokens.Find(token.token);

            if (_token == null)
            {
                return(NotFound());
            }

            User user = contextUsers.Users.Find(_token.Email);

            user.IsActive = true;

            contextUsers.SecurityLinkTokens.Remove(_token);

            await contextUsers.SaveChangesAsync();

            return(Ok());
        }
Beispiel #4
0
        public async Task <ValidateResponse> GetScheduleAsync([FromBody] TokenDTO token)
        {
            try
            {
                DateTime now       = DateTime.Parse(GetUKDateTime());
                string   dayOfWeek = GetDayofWeek();

                if (token == null)
                {
                    return new ValidateResponse {
                               result = "NotFound"
                    }
                }
                ;

                Widget wgt = context.Widgets.Include(widget => widget.User)
                             .Where(widget => widget.ID == Guid.Parse(token.token))
                             .FirstOrDefault();

                if (wgt == null)
                {
                    return new ValidateResponse {
                               result = "NotFound"
                    }
                }
                ;

                if (wgt.Status != "Active")
                {
                    return new ValidateResponse {
                               result = "NotActive"
                    }
                }
                ;

                WidgetDTO wgtDTO = new WidgetDTO(wgt);

                bool   isOpen    = false;
                string startTime = "";
                string endTime   = "";
                foreach (WeekDay day in wgtDTO.WeekDays)
                {
                    if (day.name == dayOfWeek)
                    {
                        isOpen    = day.isOpen;
                        startTime = day.startTime;
                        endTime   = day.endTime;
                    }
                }

                ValidateResponse response = new ValidateResponse();

                if (!isOpen)
                {
                    response.result = DAYCLOSED;

                    response.datetimes = BuildSchedule(now, false, wgtDTO.WeekDays);
                    return(response);
                }

                string[] startTimeSplit = startTime.Split(":. ".ToCharArray());
                int      startTimeHour  = int.Parse(startTimeSplit[0], System.Globalization.NumberStyles.Any);
                int      startTimeMin   = int.Parse(startTimeSplit[1], System.Globalization.NumberStyles.Any);

                string[] endTimeSplit = endTime.Split(":.".ToCharArray());
                int      endTimeHour  = int.Parse(endTimeSplit[0], System.Globalization.NumberStyles.Any);
                int      endTimeMin   = int.Parse(endTimeSplit[1], System.Globalization.NumberStyles.Any);

                int nowHour = now.TimeOfDay.Hours;
                int nowMin  = now.TimeOfDay.Minutes;

                if (nowHour < startTimeHour)
                {
                    response.result    = DAYCLOSED;
                    response.datetimes = BuildSchedule(now, true, wgtDTO.WeekDays);
                    return(response);
                }

                if (nowHour > endTimeHour)
                {
                    response.result    = DAYCLOSED;
                    response.datetimes = BuildSchedule(now, false, wgtDTO.WeekDays);
                    return(response);
                }


                if (nowHour == startTimeHour && nowMin < startTimeMin)
                {
                    response.result    = DAYCLOSED;
                    response.datetimes = BuildSchedule(now, true, wgtDTO.WeekDays);
                    return(response);
                }

                if (nowHour == endTimeHour && nowMin > endTimeMin)
                {
                    response.result    = DAYCLOSED;
                    response.datetimes = BuildSchedule(now, false, wgtDTO.WeekDays);
                    return(response);
                }

                response.result = DAYOPEN;

                return(response);
            }
            catch (Exception ex)
            {
                AppException exception = new AppException();
                exception.ErrorDateTime = DateTime.Now;
                exception.Message       = ex.Message;
                exception.FullString    = ex.ToString();
                context.AppExceptions.Add(exception);
                await context.SaveChangesAsync();

                throw ex;
            }

            //List<CustomDateTime> datetimes = new List<CustomDateTime>();

            //datetimes.Add(new CustomDateTime
            //{
            //    date = "Oct 20",
            //    fulldate = "October 20, 2018",
            //    today = "y",
            //    day = "Thu",
            //    fullday = "Thursday",
            //    times = new string[] { "12:00", "12:30", "13:00", "13:30" }
            //});

            //datetimes.Add(new CustomDateTime
            //{
            //    date = "Sep 10",
            //    fulldate = "September 10, 2018",
            //    today = "n",
            //    day = "Fri",
            //    fullday = "Friday",
            //    times = new string[] { "09:00", "09:30", "10:00", "10:30" }
            //});

            //datetimes.Add(new CustomDateTime
            //{
            //    date = "Sep 14",
            //    fulldate = "September 14, 2018",
            //    today = "n",
            //    day = "Wed",
            //    fullday = "Wednesday",
            //    times = new string[] { "09:30", "10:30", "11:00", "11:30" }
            //});

            //response.datetimes = datetimes;

            //return response;
        }