Пример #1
0
        public ActionResult Delete(int id)
        {
            var        customerid = Session["Id"];
            Customer   c          = db.Customers.Find(customerid);
            CartDetail deleted    = db.CartDetails.Find(id);

            c.Cart.CartDetail.Remove(deleted);
            db.Entry(c).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(Product edited, HttpPostedFileBase[] productImage, int CategoryIds, Size Size)
        {
            edited.CategoryId    = CategoryIds;
            edited.Size          = Size;
            edited.ProductImages = new List <ProductImage>();
            foreach (var item in productImage)
            {
                ProductImage p = new ProductImage();
                p.ImageURL = item.FileName;
                edited.ProductImages.Add(p);
            }
            if (ModelState.IsValid)
            {
                var old = db.Products.Find(edited.Id);
                old.Name            = edited.Name;
                old.Price           = edited.Price;
                old.Color           = edited.Color;
                old.Description     = edited.Description;
                old.ProductQuantity = edited.ProductQuantity;
                old.Size            = edited.Size;
                old.CategoryId      = edited.CategoryId;
                db.Entry(old).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(edited));
        }
Пример #3
0
 public ActionResult Edit([Bind(Include = "CategoryId,Name")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Пример #4
0
 public ActionResult Edit([Bind(Include = "Id,NameSurname,Email,PhoneNumber,Address")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Пример #5
0
        public ActionResult Edit(HttpPostedFileBase ImagePath, [Bind(Include = "ProductID,CategoryID,Name,Description,UnitPrice,Quantity,ImagePath,Status")] Product product)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (ImagePath != null && ImagePath.ContentLength > 0 && !validImageTypes.Contains(ImagePath.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
            }

            if (ModelState.IsValid)
            {
                if (ImagePath != null && ImagePath.ContentLength > 0)
                {
                    var uploadDir = "~/Upload";
                    var imagePath = Path.Combine(Server.MapPath(uploadDir), ImagePath.FileName);
                    var imageUrl  = Path.Combine(uploadDir, ImagePath.FileName);
                    ImagePath.SaveAs(imagePath);
                    product.ImagePath       = ImagePath.FileName;
                    db.Entry(product).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    db.Products.Attach(product);
                    db.Entry(product).State = EntityState.Modified;
                    db.Entry(product).Property("ImagePath").IsModified = false;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryID);
            return(View(product));
        }
Пример #6
0
        public ActionResult ResetPassword(string newPassword, string newPassword2)
        {
            bool?Control = false;

            ViewBag.CheckinPassword = "******";
            if (newPassword == newPassword2)
            {
                string   Mail    = Request.QueryString["Mail"];
                Customer Account = db.Customers.Where(x => x.Email == Mail).FirstOrDefault();
                Account.Password        = newPassword;
                db.Entry(Account).State = EntityState.Modified;
                db.SaveChanges();
                Control = true;
                RedirectToAction("Index");
            }
            return(View(Control));
        }
Пример #7
0
        public ActionResult Edit([Bind(Include = "Id,ParentId,Name")] Category category, HttpPostedFileBase Image)

        {
            if (Image != null)
            {
                string folder = Server.MapPath("/Uploads/CategoryImage/");
                Image.SaveAs(folder + Image.FileName);
                category.ImageUrl = "/Uploads/CategoryImage/" + Image.FileName;
            }
            if (ModelState.IsValid)
            {
                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Categories = db.Categories.Where(x => x.ParentId == null).ToList();
            // ViewBag.ParentId = new SelectList(db.Categories, "Id", "Name", category.ParentId);
            return(View(category));
        }