Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("UserId,AvatarPicture,Birthday,CoverPicture,Email,FirstName,IsActive,LastName,Looked,Lpoint,Password,PhoneNumber,ReferUserId,Sex,Token")] Users users)
        {
            if (id != users.UserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(users);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UsersExists(users.UserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(users));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("ProductId,AvgRating,CategoryId,Discontinued,Discount,IsDelete,IsNew,Note,Picture,ProductName,ReorderLevel,SupplierId,UnitPrice,UnitsInStock")] Products products,
                                               ICollection <IFormFile> files)
        {
            string tempImageURL = "";
            var    product      = _context.Products.SingleOrDefault(m => m.ProductId == id);

            if (ModelState.IsValid)
            {
                try
                {
                    if (product != null)
                    {
                        var uploads = Path.Combine(_environment.WebRootPath, "Image/products");
                        foreach (var file in files)
                        {
                            if (file != null)
                            {
                                string URL = uploads + "/" + file.FileName;
                                Bitmap img = convertImage.ResizeImage(Image.FromStream(file.OpenReadStream(), true, true), 400, 400);
                                img.Save(URL);
                                tempImageURL += "~/Image/products/" + file.FileName + ";";
                            }
                        }
                        product.ProductName  = products.ProductName;
                        product.Note         = products.Note;
                        product.Picture      = tempImageURL;
                        product.CategoryId   = products.CategoryId;
                        product.UnitPrice    = products.UnitPrice;
                        product.UnitsInStock = products.UnitsInStock;
                        product.Discount     = products.Discount;
                        product.SupplierId   = products.SupplierId;
                        product.ReorderLevel = products.ReorderLevel;
                        product.Discontinued = false;
                        product.IsNew        = true;
                        product.IsDelete     = false;
                        product.AvgRating    = 0;
                        _context.Update(product);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction("Index"));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsExists(products.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        return(RedirectToAction("Error"));
                    }
                }
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryName", products.CategoryId);
            ViewData["SupplierId"] = new SelectList(_context.Suppliers, "SupplierId", "CompanyName", products.SupplierId);
            return(View(products));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ShipperId,CompanyName,Description,Phone")] Shippers shippers)
        {
            var shipper = _context.Shippers.SingleOrDefault(m => m.ShipperId == id);

            shipper.CompanyName = shippers.CompanyName;
            shipper.Description = shippers.Description;
            shipper.Phone       = shippers.Phone;
            _context.Update(shipper);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ShipperId,CompanyName,Description,Phone")] Shippers shippers)
        {
            if (HttpContext.Session.GetString("UserID") == null && HttpContext.Session.GetString("Email") == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            var shipper = _context.Shippers.SingleOrDefault(m => m.ShipperId == id);

            shipper.CompanyName = shippers.CompanyName;
            shipper.Description = shippers.Description;
            shipper.Phone       = shippers.Phone;
            _context.Update(shipper);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Edit(int id, [Bind("SupplierId,Address,City,CompanyName,ContactName,Country,Fax,HomePage,Phone")] Suppliers suppliers)
        {
            var supp = _context.Suppliers.SingleOrDefault(m => m.SupplierId == id);

            supp.CompanyName = suppliers.CompanyName;
            supp.Address     = suppliers.Address;
            supp.City        = suppliers.City;
            supp.ContactName = suppliers.ContactName;
            supp.Country     = suppliers.Country;
            supp.Fax         = suppliers.Fax;
            supp.HomePage    = suppliers.HomePage;
            supp.Phone       = suppliers.Phone;

            _context.Update(supp);
            await _context.SaveChangesAsync();


            return(RedirectToAction("Index"));
        }