示例#1
0
        public async Task <IActionResult> OnPostAsync()
        {
            //Check valid user//////////////////////////////////////////////////////////////////////////////////
            ApplicationUser = await _userManager.GetUserAsync(User);  // User = logged in user (built in magic)

            if (ApplicationUser == null)
            {
                return(NotFound());
            }
            bool isCustomer = await _userManager.IsInRoleAsync(ApplicationUser, "customer");

            if (!isCustomer)
            {
                return(NotFound());
            }

            int SelectedCourt;

            if (SelectedCourtId == null)
            {
                SelectedCourt = 1;
            }
            else
            {
                SelectedCourt = int.Parse(SelectedCourtId);
            }

            int BookingStatusId = await _context.BookingStatus
                                  .Where(a => a.Status == "Pending")
                                  .Select(a => a.Id).SingleOrDefaultAsync();

            var booking = new Booking()
            {
                ApplicationUserId = ApplicationUser.Id,
                CreatedDate       = DateTime.Now,
                BookingDate       = SelectedBookingDate,
                CourtId           = SelectedCourt,
                BookingStatusId   = BookingStatusId
            };

            _context.Booking.Add(booking);
            await _context.SaveChangesAsync();

            for (var i = 0; i < AreChecked.Count(); i++)
            {
                var slot        = AreChecked[i] + 1;
                var bookedSlots = new BookedSlot()
                {
                    Slot      = slot,
                    BookingId = booking.Id
                };
                _context.BookedSlot.Add(bookedSlots);
                await _context.SaveChangesAsync();
            }

            StatusMessage = "New booking has been added";
            return(RedirectToPage("./Index"));
        }
        public HttpStatusCodeResult BookEvent(DateTimeOffset eventStart, DateTimeOffset eventEnd, string name, string id, string bookableId)
        {
            var userName     = User.Identity.Name;
            var userId       = UserStore.GetId(userName);
            var bookableslot = new BookedSlot();

            bookableslot.Start      = eventStart;
            bookableslot.End        = eventEnd;
            bookableslot.BookableId = Guid.Parse(bookableId);
            bookableslot.Consumers.Add(userId.Value);
            bookableslot.Id = Guid.Parse(id);

            var consumer = ConsumerBroker.GetConsumer(userId.Value);
            var result   = consumer.BookSlot(bookableslot);


            return(new HttpStatusCodeResult(200, result.ToString()));
        }
 public Task AddSlot(BookedSlot slot)
 {
     return(_collection.InsertOneAsync(slot));
 }