コード例 #1
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Customer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CustomerExists(Customer.CustomerId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #2
0
ファイル: Create.cshtml.cs プロジェクト: romils1994/foodies
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            ViewData["CustomerId"]        = new SelectList(_context.Customer, "CustomerId", "Name");
            ViewData["DeliveryPartnerId"] = new SelectList(_context.DeliveryPartner, "DeliveryPartnerId", "Name");
            ViewData["RestaurantId"]      = new SelectList(_context.Restaurant, "RestaurantId", "Name");

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var      restaurantId = Order.RestaurantId;
            TimeSpan orderTime    = Order.Date.TimeOfDay;
            var      restaurant   = await _context.Restaurant.Where(x => x.RestaurantId == restaurantId).ToListAsync();

            TimeSpan restaurantStartTime = restaurant[0].StartTime;
            TimeSpan restaurantEndTime   = restaurant[0].EndTime;

            if ((orderTime < restaurantStartTime) || (orderTime > restaurantEndTime))
            {
                ModelState.AddModelError("Order.Date", "The Order Time should be within Restaurant Start Time and End Time");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            _context.Order.Add(Order);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
コード例 #3
0
ファイル: Create.cshtml.cs プロジェクト: romils1994/foodies
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            TimeSpan duration = Restaurant.EndTime.Subtract(Restaurant.StartTime);

            if (TimeSpan.Compare(duration, TimeSpan.Zero) <= 0)
            {
                ModelState.AddModelError("Restaurant.EndTime", "The Restaurant End Time can not be less or equal to than Start Time");
            }
            var  licenseNumber = Restaurant.LicenseNumber;
            bool licenseNumberAlreadyExists = await _context.Restaurant.AnyAsync(x => x.LicenseNumber == licenseNumber);

            if (licenseNumberAlreadyExists)
            {
                ModelState.AddModelError("Restaurant.LicenceNumber", "Restaurant with this license Number already exists");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
コード例 #4
0
ファイル: Create.cshtml.cs プロジェクト: romils1994/foodies
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            return(RedirectToPage("./Index"));
        }
コード例 #5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            ViewData["CustomerId"]        = new SelectList(_context.Customer, "CustomerId", "Name");
            ViewData["DeliveryPartnerId"] = new SelectList(_context.DeliveryPartner, "DeliveryPartnerId", "Name");
            ViewData["RestaurantId"]      = new SelectList(_context.Restaurant, "RestaurantId", "Name");

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            var      restaurantId = Order.RestaurantId;
            TimeSpan orderTime    = Order.Date.TimeOfDay;
            var      restaurant   = await _context.Restaurant.Where(x => x.RestaurantId == restaurantId).ToListAsync();

            TimeSpan restaurantStartTime = restaurant[0].StartTime;
            TimeSpan restaurantEndTime   = restaurant[0].EndTime;

            if ((orderTime < restaurantStartTime) || (orderTime > restaurantEndTime))
            {
                ModelState.AddModelError("Order.Date", "The Order Time should be within Restaurant Start Time and End Time");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(Order.OrderId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Customer = await _context.Customer.FindAsync(id);

            if (Customer != null)
            {
                _context.Customer.Remove(Customer);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #7
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Restaurant = await _context.Restaurant.FindAsync(id);

            if (Restaurant != null)
            {
                _context.Restaurant.Remove(Restaurant);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
コード例 #8
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            TimeSpan duration = Restaurant.EndTime.Subtract(Restaurant.StartTime);

            if (TimeSpan.Compare(duration, TimeSpan.Zero) <= 0)
            {
                ModelState.AddModelError("Restaurant.EndTime", "The Restaurant End Time can not be less or equal to than Start Time");
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Restaurant).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(Restaurant.RestaurantId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }