Esempio n. 1
0
        public ActionResult Edit(HttpPostedFileBase ProductImage, int id, ProductTB editProduct)
        {
            try
            {
                // TODO: Add update logic here
                ProductTB updateProduct = objdc.ProductTBs.SingleOrDefault(x => x.ProductId == id);
                string    _FileName     = "";

                if (ProductImage != null && ProductImage.ContentLength > 0)
                {
                    _FileName = Path.GetFileName(ProductImage.FileName);
                    string path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);
                    ProductImage.SaveAs(path);
                    updateProduct.Image = _FileName;
                }
                //updateProduct = editProduct;

                UpdateModel(updateProduct);
                objdc.SubmitChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 2
0
        // DELETE: api/Product/5
        public void Delete(int id)
        {
            ProductTB p = dc.ProductTBs.FirstOrDefault(s => s.ProductId == id);

            dc.ProductTBs.DeleteOnSubmit(p);
            dc.SubmitChanges();
        }
Esempio n. 3
0
        //end ---------------------------------------



        //this will return the detail page
        //start ------------------------------
        public ActionResult DetailPage(int Id)
        {
            ProductReviewViewModel pvm = new ProductReviewViewModel();
            ProductTB              tb  = new ProductTB();
            List <ReviewTB>        rtb = new List <ReviewTB>();
            List <ReviewViewModel> rv  = new List <ReviewViewModel>();

            if (Id != 0)
            {
                tb  = _db.ProductTBs.Where(p => p.ProductId == Id).FirstOrDefault();
                rtb = _db.ReviewTBs.Where(p => p.ProductId == Id).ToList();
            }
            else
            {
                tb  = _db.ProductTBs.Where(p => p.ProductId == 4).FirstOrDefault();
                rtb = _db.ReviewTBs.Where(p => p.ProductId == 4).ToList();
            }

            pvm.ProductId       = tb.ProductId;
            pvm.ProductName     = tb.ProductName;
            pvm.ProductDetail   = tb.ProductDetail;
            pvm.ProductImageUrl = tb.ProductImageUrl;
            pvm.Price           = tb.Price;
            foreach (var item in rtb)
            {
                rv.Add(new ReviewViewModel()
                {
                    ReviewId = item.ReviewId, StarNumber = item.NumberOfStar, Message = item.Comment, UserName = item.UserTB.UserName, UserId = item.UserId, Date = item.Date
                });
            }
            pvm.RVM = rv;
            return(View(pvm));
        }
Esempio n. 4
0
        public ActionResult AddProduct(ProductViewModel pv)
        {
            ProductTB pt = new ProductTB();

            pt.ProductName     = pv.ProductName;
            pt.ProductDetail   = pv.ProductDetail;
            pt.Price           = pv.Price;
            pt.ProductImageUrl = pv.ProductImageUrl;
            _db.ProductTBs.Add(pt);
            _db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 5
0
        // PUT: api/Product/5
        public void Put([FromBody] ProductTB product)
        {
            var olddata = dc.ProductTBs.Where(s => s.ProductId == product.ProductId).FirstOrDefault();

            olddata.ProductName = product.ProductName;
            olddata.CategoryId  = product.CategoryId;
            olddata.MfgDate     = product.MfgDate;
            olddata.Price       = product.Price;
            olddata.IsAvailable = product.IsAvailable;

            dc.SubmitChanges();
        }
        public ActionResult Create(ProductTB pdata)
        {
            try
            {
                objinterface.InsertData(pdata);
                objinterface.save();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
 public ActionResult Delete(int id, ProductTB data)
 {
     try
     {
         var dataa = objinterface.GetDataById(s => s.ProductId == id);
         // TODO: Add delete logic here
         objinterface.DeleteData(dataa);
         objinterface.save();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 8
0
 public ActionResult Create(HttpPostedFileBase ProductImage, ProductTB NewProduct)
 {
     try
     {
         string _FileName = "";
         if (ProductImage.ContentLength > 0)
         {
             _FileName = Path.GetFileName(ProductImage.FileName);
             string path = Path.Combine(Server.MapPath("~/UploadedFiles"), _FileName);
             ProductImage.SaveAs(path);
         }
         NewProduct.Image = _FileName;
         objdc.ProductTBs.InsertOnSubmit(NewProduct);
         objdc.SubmitChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Edit(int id, ProductTB product)
        {
            try
            {
                var data = objinterface.GetDataById(s => s.ProductId == id);
                data.ProductName = product.ProductName;
                data.MfgDate     = product.MfgDate;
                data.Price       = product.Price;
                data.CategoryId  = product.CategoryId;
                objinterface.save();


                // TODO: Add update logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 10
0
 // POST: api/Product
 public void Post([FromBody] ProductTB product)
 {
     dc.ProductTBs.InsertOnSubmit(product);
     dc.SubmitChanges();
 }