Beispiel #1
0
        public IActionResult isAvailable(long id, string requestDateFrom, string requestDateTo)
        {
            DateTime     fromDateToCheck = DateTime.Parse(requestDateFrom);
            DateTime     toDateToCheck   = DateTime.Parse(requestDateTo);
            Date         dateOfWeek      = dbContext.Date.First(t => t.Title == fromDateToCheck.DayOfWeek.ToString());
            Organization organization    = dbContext.Organization.FirstOrDefault(t => t.ID == id);

            if (organization == null)
            {
                return(NotFound());
            }
            else if (dateOfWeek == null || fromDateToCheck == null || toDateToCheck == null)
            {
                return(BadRequest());
            }

            OrganizationDateRelation organizationScheduleAtDay = dbContext.OrganizationDateRelation
                                                                 .FirstOrDefault(t => t.Organization_ID == organization && t.Date_ID == dateOfWeek);

            TimeSpan fromTimeToCheck = TimeSpan.Parse(fromDateToCheck.ToString("HH:mm"));
            TimeSpan toTimeToCheck   = TimeSpan.Parse(toDateToCheck.ToString("HH:mm"));
            Tuple <TimeSpan, TimeSpan> scheduleRange = new Tuple <TimeSpan, TimeSpan>((TimeSpan)organizationScheduleAtDay.From, (TimeSpan)organizationScheduleAtDay.To);
            Tuple <TimeSpan, TimeSpan> requestRange  = new Tuple <TimeSpan, TimeSpan>(fromTimeToCheck, toTimeToCheck);

            return(Ok(
                       !(scheduleRange.Item1 > scheduleRange.Item2 || requestRange.Item1 > requestRange.Item2) &&
                       (scheduleRange.Item1 <= requestRange.Item1 && requestRange.Item1 <= scheduleRange.Item2 &&
                        scheduleRange.Item1 <= requestRange.Item2 && requestRange.Item2 <= scheduleRange.Item2)
                       ));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([FromBody] JObject data)
        {
            ApplicationUser user = await _userManager.FindByNameAsync(_userManager.GetUserId(User));

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            Organization organization = new Organization();

            organization.User  = user;
            organization.Title = data["title"].ToString();

            dbContext.Organization.Add(organization);
            dbContext.SaveChanges();

            var schedule = data["schedule"];

            if (schedule != null)
            {
                JObject[] scheduleList = schedule.ToObject <JObject[]>();

                for (int i = 0; i < scheduleList.Length; i++)
                {
                    int  dateId = scheduleList[i]["id"].ToObject <int>();
                    Date date   = dbContext.Date.Where(t => t.ID == dateId).FirstOrDefault();
                    if (date != null)
                    {
                        OrganizationDateRelation organizationDateRelation = new OrganizationDateRelation {
                            Organization_ID = organization,
                            Date_ID         = date,
                            From            = scheduleList[i]["from"].ToObject <TimeSpan>(),
                            To            = scheduleList[i]["to"].ToObject <TimeSpan>(),
                            IsDayAndNight = scheduleList[i]["isAllDayAndNight"] == null ? false : scheduleList[i]["isAllDayAndNight"].ToObject <bool>(),
                            IsHoliday     = scheduleList[i]["isHoliday"] == null ? false : scheduleList[i]["isHoliday"].ToObject <bool>()
                        };

                        dbContext.OrganizationDateRelation.Add(organizationDateRelation);
                    }
                }
            }

            dbContext.SaveChanges();

            return(Ok());
        }