예제 #1
0
        public ActionResult Edit(int?id, HttpPostedFileBase upload)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var product = db.Products.Find(id);

            if (TryUpdateModel(product, "",
                               new string[] { "Name", "Description", "Price", "CategoryId" }))
            {
                try
                {
                    if (upload != null && upload.ContentLength > 0)
                    {
                        /* This is used when storing photos in the filesystem not in database.FilePath tbl has FilePathID,FileName,FileType,ProductID
                         * var photo = new FilePath
                         * {
                         *      FileName = System.IO.Path.GetFileName(upload.FileName),
                         * //FileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(upload.FileName), use this to guarantee unique filename so files dont overide each other
                         *      FileType = 2
                         * };
                         * product.FilePaths = new List<FilePath>();
                         * product.FilePaths.Add(photo);
                         */

                        if (product.FilePaths.Any(f => f.FileType == 1))
                        {
                            db.FilePaths.Remove(product.FilePaths.First(f => f.FileType == 1));
                        }
                        var photo = new FilePath
                        {
                            FileName    = System.IO.Path.GetFileName(upload.FileName),
                            FileType    = 1,
                            ContentType = upload.ContentType
                        };
                        using (var reader = new System.IO.BinaryReader(upload.InputStream))
                        {
                            photo.Content = reader.ReadBytes(upload.ContentLength);
                        }
                        product.FilePaths = new List <FilePath> {
                            photo
                        };
                    }

                    db.Entry(product).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
            return(View(product));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "BranchId,BranchName,Phone,Email,Address,AreaCode")] Branch branch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(branch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(branch));
 }
 public ActionResult Edit([Bind(Include = "CategoryTypeId,Name,Description")] CategoryType categoryType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoryType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoryType));
 }
예제 #4
0
 public ActionResult Edit([Bind(Include = "CategoryId,Name,CategoryTypeId,Description")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryTypeId = new SelectList(db.CategoryTypes, "CategoryTypeId", "Name", category.CategoryTypeId);
     return(View(category));
 }
예제 #5
0
 public ActionResult Edit([Bind(Include = "FilePathId,FileName,FileType,ProductId,ContentType,Content")] FilePath filePath)
 {
     if (ModelState.IsValid)
     {
         db.Entry(filePath).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Name", filePath.ProductId);
     return(View(filePath));
 }
 public ActionResult Edit([Bind(Include = "Id,OrderId,ProductId,Count,Total")] T_Shop_OFProduct t_Shop_OFProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(t_Shop_OFProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderId   = new SelectList(db.T_Shop_OrderForm, "Id", "FahuoId", t_Shop_OFProduct.OrderId);
     ViewBag.ProductId = new SelectList(db.T_Shop_Product, "Id", "Name", t_Shop_OFProduct.ProductId);
     return(View(t_Shop_OFProduct));
 }
 public ActionResult Edit([Bind(Include = "BranchProductId,ProductId,BranchId,Quantity")] BranchProduct branchProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(branchProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.BranchId  = new SelectList(db.Branches, "BranchId", "BranchName", branchProduct.BranchId);
     ViewBag.ProductId = new SelectList(db.Products, "ProductId", "Name", branchProduct.ProductId);
     return(View(branchProduct));
 }
예제 #8
0
 public ActionResult Edit([Bind(Include = "Id,UserId,ProductId,Count,Total,Time")] T_Shop_Basket t_Shop_Basket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(t_Shop_Basket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.T_Shop_Product, "Id", "Name", t_Shop_Basket.ProductId);
     ViewBag.UserId    = new SelectList(db.T_Shop_Users, "Id", "Name", t_Shop_Basket.UserId);
     return(View(t_Shop_Basket));
 }