コード例 #1
0
 // Get :Category/Delete
 public ActionResult Delete(int id)
 {
     try
     {
         category modifyCategory = db.categories.Find(id);
         if (modifyCategory == null)
         {
             return(HttpNotFound());
         }
         modifyCategory.activeFlag      = 0;
         db.Entry(modifyCategory).State = EntityState.Modified;
         db.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         foreach (var eve in e.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         /*    throw;*/
     }
     return(RedirectToAction("Index"));
 }
コード例 #2
0
        // GET :Brand/Delete /
        public ActionResult Delete(int id)
        {
            brand modifybrand = db.brands.Find(id);

            if (modifybrand == null)
            {
                return(HttpNotFound());
            }
            modifybrand.activeFlag      = 0;
            db.Entry(modifybrand).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "id,activeLag,createDate,updateDate")] product product2, int catagoryId, int brandId, string name, HttpPostedFileBase imgMain, string code, string description)
 {
     if (ModelState.IsValid)
     {
         product modifyproduct = db.products.Find(product2.id);
         if (modifyproduct != null)
         {
             if (imgMain != null && imgMain.ContentLength > 0)
             {
                 string fileName = System.IO.Path.GetFileName(imgMain.FileName);
                 string urlImage = Server.MapPath("~/Image/product/" + fileName);
                 imgMain.SaveAs(urlImage);
                 modifyproduct.imgMain     = "Image/product/" + fileName;
                 modifyproduct.brandId     = brandId;
                 modifyproduct.catagoryId  = catagoryId;
                 modifyproduct.name        = name;
                 modifyproduct.code        = code;
                 modifyproduct.description = description;
                 modifyproduct.updateDate  = DateTime.Now;
             }
             if (name != null)
             {
                 modifyproduct.name       = name;
                 modifyproduct.updateDate = DateTime.Now;
             }
             if (catagoryId != 0)
             {
                 modifyproduct.catagoryId = catagoryId;
                 modifyproduct.updateDate = DateTime.Now;
             }
             if (brandId != 0 && catagoryId != 0)
             {
                 modifyproduct.brandId    = brandId;
                 modifyproduct.catagoryId = catagoryId;
                 modifyproduct.updateDate = DateTime.Now;
             }
         }
         db.Entry(modifyproduct).State = System.Data.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product2));
 }