Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,PlacedInCart,Quantity,UnitPrice,Shipping,CheckedOut")] OrderDetail orderDetail)
        {
            if (id != orderDetail.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orderDetail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderDetailExists(orderDetail.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(orderDetail));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Recipient,Address1,Address2,City,State,Zip,Country,Phone")] Address address)
        {
            if (id != address.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(address);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AddressExists(address.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(address));
        }
Пример #3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Registered,LastVisited,TimesVisited,EmailAddress")] Customer customer)
        {
            if (id != customer.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,DateOrdered,Subtotal,Shipping,Total")] Order order)
        {
            if (id != order.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(order));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,Price,Shipping,ImageUpload,Category")] ProductVM product)
        {
            if (id != product.ID)
            {
                return(NotFound());
            }

            // validate image upload
            if (product.ImageUpload == null || product.ImageUpload.Length == 0)
            {
                ModelState.AddModelError("ImageUpload", "This field is required");
            }
            else if (!validImageTypes.Contains(product.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }


            if (ModelState.IsValid)
            {
                // Copy ViewModel info to Model
                var editedProduct = _context.Product.Find(id);
                editedProduct.Name        = product.Name;
                editedProduct.Description = product.Description;
                editedProduct.Price       = product.Price;
                editedProduct.Shipping    = product.Shipping;
                editedProduct.Category    = product.Category;

                // Save image to disk and store filepath in model
                if (product.ImageUpload != null && product.ImageUpload.Length != 0)
                {
                    var imageDir  = "/images";
                    var imagePath = Path.Combine(_env.WebRootPath, "images", product.ImageUpload.FileName);
                    //var imageUrl = Path.Combine(imageDir, product.ImageUpload.FileName);
                    var imageUrl = imageDir + "/" + product.ImageUpload.FileName;
                    product.ImageUpload.CopyTo(new FileStream(imagePath, FileMode.Create));
                    editedProduct.ImageURL = imageUrl;
                }

                try
                {
                    _context.Update(editedProduct);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }