public async Task <IActionResult> Edit(int id, [Bind("Id,DeliveryAgentId,LunchPackId,CustomerId,NumberOfPacks,Address")] OnlineDelivery onlineDelivery)
        {
            if (id != onlineDelivery.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(onlineDelivery);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OnlineDeliveryExists(onlineDelivery.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]      = new SelectList(_context.Customer, "Id", "Id", onlineDelivery.CustomerId);
            ViewData["DeliveryAgentId"] = new SelectList(_context.DeliveryAgent, "Id", "Id", onlineDelivery.DeliveryAgentId);
            ViewData["LunchPackId"]     = new SelectList(_context.LunchPack, "Id", "Id", onlineDelivery.LunchPackId);
            return(View(onlineDelivery));
        }
        public async Task <IActionResult> Create([Bind("Id,DeliveryAgentId,LunchPackId,CustomerId,NumberOfPacks,Address")] OnlineDelivery onlineDelivery)
        {
            if (ModelState.IsValid)
            {
                _context.Add(onlineDelivery);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"]      = new SelectList(_context.Customer, "Id", "Id", onlineDelivery.CustomerId);
            ViewData["DeliveryAgentId"] = new SelectList(_context.DeliveryAgent, "Id", "Id", onlineDelivery.DeliveryAgentId);
            ViewData["LunchPackId"]     = new SelectList(_context.LunchPack, "Id", "Id", onlineDelivery.LunchPackId);
            return(View(onlineDelivery));
        }
Example #3
0
        private static void LoadDeliveryTypes(DalContext dalContext)
        {
            var directDeliveryPrice = new Price()
            {
                GrossAmount = 0,
                NetAmount   = 0,
                VatRate     = 8
            };
            var directDelivery = new DirectDelivery()
            {
                ServiceFee = directDeliveryPrice,
                Name       = "Direct delivery"
            };

            var onlineDeliveryPrice = new Price()
            {
                GrossAmount = 3,
                NetAmount   = 2.78m,
                VatRate     = 8
            };
            var onlineDelivery = new OnlineDelivery()
            {
                ServiceFee = onlineDeliveryPrice,
                Name       = "Online delivery"
            };

            var dispatchDeliveryPrice = new Price()
            {
                GrossAmount = 15,
                NetAmount   = 13.89m,
                VatRate     = 8
            };
            var dispatchDelivery = new DispatchDelivery()
            {
                ServiceFee = dispatchDeliveryPrice,
                Name       = "Dispatch delivery"
            };

            dalContext.Prices.Add(directDeliveryPrice);
            dalContext.DirectDeliveries.Add(directDelivery);

            dalContext.Prices.Add(onlineDeliveryPrice);
            dalContext.OnlineDeliveries.Add(onlineDelivery);

            dalContext.Prices.Add(dispatchDeliveryPrice);
            dalContext.DispatchDeliveries.Add(dispatchDelivery);

            dalContext.SaveChanges();
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

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

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            OnlineDelivery = await _context.OnlineDelivery
                             .Include(o => o.Customer)
                             .Include(o => o.DeliveryAgent)
                             .Include(o => o.LunchPack).FirstOrDefaultAsync(m => m.Id == id);

            if (OnlineDelivery == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #6
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            OnlineDelivery = await _context.OnlineDelivery
                             .Include(o => o.Customer)
                             .Include(o => o.DeliveryAgent)
                             .Include(o => o.LunchPack).FirstOrDefaultAsync(m => m.Id == id);

            if (OnlineDelivery == null)
            {
                return(NotFound());
            }
            ViewData["CustomerId"]      = new SelectList(_context.Customer, "Id", "Name");
            ViewData["DeliveryAgentId"] = new SelectList(_context.DeliveryAgent, "Id", "Name");
            ViewData["LunchPackId"]     = new SelectList(_context.LunchPack, "Id", "Description");
            return(Page());
        }