コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Location,ActiveCashiers,MaxCapacity")] Shop shop)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shop);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shop));
        }
コード例 #2
0
ファイル: UsersController.cs プロジェクト: LeoKuyper/ShopTime
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName")] User user)
        {
            if (ModelState.IsValid)
            {
                //user.Id = Guid.NewGuid();
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,OwnerID,ShopId,BookingTime,BookingState")] Booking bookingModel)
        {
            // Make sure that the Booking is related to the user on create
            if (ModelState.IsValid)
            {
                // 1. Create a new Booking object
                var booking = new Booking
                {
                    Id           = bookingModel.Id,
                    ShopId       = bookingModel.ShopId,
                    BookingTime  = localDate,
                    BookingState = "YouCanEnter",
                    Owner        = _userManager.GetUserAsync(User).Result
                };

                if (booking.Shops != null)
                {
                    _logger.LogInformation("Counting Shops");

                    List <Shop> allShops = _context.Shop.Where(shop => bookingModel.Shops.Contains(shop.Name)).ToList();

                    foreach (Shop shop in allShops)
                    {
                        _logger.LogInformation(shop.Name);
                    }
                }
                else
                {
                    _logger.LogInformation("Not Counting Shops");
                }

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bookingModel));
        }