Exemple #1
0
 public void Insert(ProductView model)
 {
     using (var rep = new ProductRepository())
        {
        rep.Insert(ConvertToProduct(model));
        }
 }
Exemple #2
0
        public void Update(ProductView modelView)
        {
            using (var rep = new ProductRepository())
               {
               var dev = rep.GetById(modelView.Id);

               if (dev != null)
               {

                   dev.Name = modelView.Name;
                   dev.Description = modelView.Description;
                   dev.price = modelView.price;
                   dev.SerialCode = modelView.SerialCode;
                   dev.ImageUrl = modelView.ImageUrl;
                   dev.CategoryId = modelView.CategoryId;
                   dev.BrandId = modelView.BrandId;

                   rep.Update(dev);
               }
               }
        }
Exemple #3
0
        public ActionResult Create(ProductView model, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string str = file.FileName.Substring(file.FileName.Length - 3);
                    string path = string.Empty;
                    path = Server.MapPath("~/Content/Images/");
                    file.SaveAs(path + file.FileName);

                    model.ImageUrl = file.FileName;
                    obj.Insert(model);
                    TempData["message"] = string.Format("{0} has been created!", model.Name);
                    ViewBag.CategoryId = new SelectList(_category.ViewAll(), "CategoryId", "CategoryName");
                    ViewBag.BrandId = new SelectList(_brand.ViewAll(), "BrandId", "BrandName");
                }
                return RedirectToAction("Index");
            }

            return View(model);
        }
Exemple #4
0
        private static Products ConvertToProduct(ProductView modelView)
        {
            var dev = new Products
               {

               Id = modelView.Id,
               Name = modelView.Name,
               Description = modelView.Description,
               price = modelView.price,
               SerialCode = modelView.SerialCode,
               ImageUrl = modelView.ImageUrl,
               CategoryId = modelView.CategoryId,
               BrandId = modelView.BrandId,

               };
               return dev;
        }
Exemple #5
0
        public ActionResult Update(ProductView model, int id, HttpPostedFileBase file)
        {
            try
            {
                if (!ModelState.IsValid)
                model.Id = id;
                string str = file.FileName.Substring(file.FileName.Length - 3);
                string path = string.Empty;
                path = Server.MapPath("~/Content/Images/");
                file.SaveAs(path + file.FileName);

                model.ImageUrl = file.FileName;
                obj.Update(model);

                return RedirectToAction("Index");
            }
            catch
            {
                ViewBag.CategoryId = new SelectList(_category.ViewAll(), "CategoryId", "CategoryName");
                ViewBag.BrandId = new SelectList(_brand.ViewAll(), "BrandId", "BrandName");
                return View(model);

            }
        }