示例#1
0
        public async Task <IActionResult> AssignPackages(AssignDMViewModel deliveryMan)
        {
            foreach (var package in deliveryMan.Packages)
            {
                var tmpPackage = await _context.Packages.Where(m => m.Id == package).FirstOrDefaultAsync();

                tmpPackage.DeliveryManId = deliveryMan.Id;
                tmpPackage.AssignDate    = DateTime.Now;
                tmpPackage.Status        = 5;

                _context.Update(tmpPackage);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction(nameof(Index)));
        }
示例#2
0
        public async Task <IActionResult> AssignPackages(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var deliveryMan = await _context.DeliveryMans.FindAsync(id);

            if (deliveryMan == null)
            {
                return(NotFound());
            }
            AssignDMViewModel deliveryMan1 = new AssignDMViewModel();

            deliveryMan1.Id   = deliveryMan.Id;
            deliveryMan1.Name = deliveryMan.Name;

            ViewData["Packages"] = new SelectList(_context.Packages.Where(m => m.Status == 4 && m.DeliveryManId == null), "Id", "TrackingNumber");
            return(View(deliveryMan1));
        }