public async Task <bool> AddUserTimeSlotAsync(UserTimeSlotModel userTimeSlotModel)
        {
            _context.UserTimeSlot.Add(userTimeSlotModel);
            var saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
Beispiel #2
0
        public async Task <IActionResult> AddUserTimeSlot(UserTimeSlotBindingModel userTimeSlotBindingModel)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var parsedDate  = userTimeSlotBindingModel.TimeSlotDescription.Split('-');
            var trimedDates = parsedDate.Select(x => x.Trim()).ToList();
            var startTime   = DateTime.Parse(trimedDates[0]);
            var endTime     = DateTime.Parse(trimedDates[1]);

            var timeSlot = await _timeSlotService.GetTimeSlotByTimeAsync(startTime, endTime);

            var userTimeSlotModel = new UserTimeSlotModel
            {
                IdentityUser  = currentUser,
                TimeSlotModel = timeSlot
            };

            var successful = await _userTimeSlotService.AddUserTimeSlotAsync(userTimeSlotModel);

            if (!successful)
            {
                return(BadRequest("Could not add the user time slot"));
            }

            return(RedirectToAction("Index"));
        }