// 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"));
 }
Example #2
0
        public JsonResult addVoucher(VoucherForm voucherForm)
        {
            System.Diagnostics.Debug.WriteLine("name " + voucherForm.Name);
            System.Diagnostics.Debug.WriteLine("product id " + voucherForm.ProductId);
            System.Diagnostics.Debug.WriteLine("voucher id " + voucherForm.VoucherId);
            System.Diagnostics.Debug.WriteLine("price " + voucherForm.Price);
            System.Diagnostics.Debug.WriteLine("start " + voucherForm.StartDate);
            System.Diagnostics.Debug.WriteLine("end " + voucherForm.EndDate);
            string message = "";


            //update
            if (voucherForm.VoucherId != 0)
            {
                voucher  v         = db.vouchers.Find(voucherForm.VoucherId);
                DateTime startDate = DateTime.Parse(voucherForm.StartDate);

                DateTime endDate = DateTime.Parse(voucherForm.EndDate);
                v.startDate = startDate;
                v.endDate   = endDate;
                v.name      = voucherForm.Name;
                v.product   = db.products.Find(voucherForm.ProductId);
                v.price     = voucherForm.Price;

                db.Entry(v).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                voucher v = new voucher();
                v.name    = voucherForm.Name;
                v.price   = voucherForm.Price;
                v.product = db.products.Find(voucherForm.ProductId);
                DateTime startDate = DateTime.Parse(voucherForm.StartDate);

                DateTime endDate = DateTime.Parse(voucherForm.EndDate);
                v.startDate  = startDate;
                v.endDate    = endDate;
                v.createDate = DateTime.Now;
                v.updateDate = DateTime.Now;
                v.activeFlag = 1;
                v.status     = 1;

                this.db.vouchers.Add(v);
                this.db.SaveChanges();

                message = "SUCCESS";
            }



            return(Json(new { Message = message }, JsonRequestBehavior.AllowGet));
        }
Example #3
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"));
        }
Example #4
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.categoryId  = 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.categoryId = catagoryId;
                 modifyproduct.updateDate = DateTime.Now;
             }
             if (brandId != 0 && catagoryId != 0)
             {
                 modifyproduct.brandId    = brandId;
                 modifyproduct.categoryId = catagoryId;
                 modifyproduct.updateDate = DateTime.Now;
             }
         }
         db.Entry(modifyproduct).State = System.Data.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product2));
 }