Ejemplo n.º 1
0
        // GET: Product/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            productModel productModel = db.productmodel.Find(id);

            if (productModel.sellerID != User.Identity.GetUserId())
            {
                TempData["ErrorMessage"] = "You may not edit a product that is not your own.";
                return(RedirectToAction("Index"));
            }
            createProductViewModel vm = modelToView(productModel);

            vm.seller = db.Users.Find(productModel.sellerID);
            if (productModel.sellerID != User.Identity.GetUserId())
            {
                ViewBag.StatusMessage = "You cannot edit a product that is not yours."; return(RedirectToAction("Index"));
            }
            vm.unitList = new List <SelectListItem>();
            foreach (var unit in db.unitsModel.ToList())
            {
                vm.unitList.Add(new SelectListItem {
                    Text = unit.unitAbvr, Value = unit.ID.ToString()
                });
            }
            if (productModel == null)
            {
                return(HttpNotFound());
            }
            return(View(vm));
        }
Ejemplo n.º 2
0
        public productModel viewToModel(createProductViewModel oldModel)
        {
            productModel newModel = new productModel();

            newModel.ID              = oldModel.ID;
            newModel.address         = oldModel.address;
            newModel.zipcode         = oldModel.zipcode;
            newModel.city            = oldModel.city;
            newModel.state           = oldModel.state;
            newModel.images          = oldModel.images;
            newModel.categoryID      = oldModel.categoryID;
            newModel.productCategory = oldModel.category;
            newModel.price           = oldModel.price;
            newModel.qtyAvail        = oldModel.qtyAvail;
            newModel.qtyRemain       = oldModel.qtyRemain;
            newModel.productName     = oldModel.productName;
            newModel.unitQTY         = oldModel.unitQty;
            newModel.ratings         = oldModel.ratings;
            newModel.unitID          = oldModel.unitID;
            newModel.sellerID        = oldModel.sellerID;
            newModel.dateListed      = oldModel.dateListed;
            newModel.tags            = new List <string>();
            if (oldModel.tags != null)
            {
                newModel.tags = oldModel.tags.Split(',').ToList();
            }
            return(newModel);
        }
Ejemplo n.º 3
0
 public ActionResult createProductStepOne(createProductViewModel viewModel)
 {
     if (viewModel.categoryID > 0)
     {
         return(RedirectToAction("Create", new { categoryID = viewModel.categoryID }));
     }
     else
     {
         return(View(viewModel));
     }
 }
Ejemplo n.º 4
0
        public ActionResult Edit(createProductViewModel viewModel)
        {
            productModel productmodel = viewToModel(viewModel);

            if (ModelState.IsValid)
            {
                db.Entry(productmodel).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Ejemplo n.º 5
0
        //CREATE PRODUCT STEP ONE [GET]
        public ActionResult createProductStepOne()
        {
            createProductViewModel viewModel  = new createProductViewModel();
            List <productCategory> categories = db.productCategory.ToList();

            viewModel.categories = new List <SelectListItem>();
            viewModel.categories.Add(new SelectListItem {
                Text = "New Category", Value = "-1"
            });
            foreach (productCategory category in categories)
            {
                viewModel.categories.Add(new SelectListItem {
                    Text = category.categoryName, Value = category.ID.ToString()
                });
            }
            return(View(viewModel));
        }
Ejemplo n.º 6
0
        public createProductViewModel modelToView(productModel model)
        {
            createProductViewModel viewModel = new createProductViewModel();

            viewModel.ID          = model.ID;
            viewModel.dateListed  = model.dateListed;
            viewModel.address     = model.address;
            viewModel.zipcode     = model.zipcode;
            viewModel.city        = model.city;
            viewModel.state       = model.state;
            viewModel.images      = model.images;
            viewModel.categoryID  = model.categoryID;
            viewModel.category    = model.productCategory;
            viewModel.price       = model.price;
            viewModel.qtyAvail    = model.qtyAvail;
            viewModel.qtyRemain   = model.qtyRemain;
            viewModel.productName = model.productName;
            viewModel.unitQty     = model.unitQTY;
            viewModel.ratings     = model.ratings;
            viewModel.unitID      = model.unitID;
            viewModel.sellerID    = model.sellerID;
            if (model.tags != null)
            {
                foreach (string tag in model.tags)
                {
                    if (tag == model.tags.Last())
                    {
                        viewModel.tags += tag;
                    }
                    else
                    {
                        viewModel.tags += (tag + ',');
                    }
                }
            }
            else
            {
                viewModel.tags = "";
            }
            return(viewModel);
        }
Ejemplo n.º 7
0
 public ActionResult Create(createProductViewModel oldModel)
 {
     if (oldModel.categoryID == -1)
     {
         return(RedirectToAction("createCategory"));
     }
     oldModel.category  = db.productCategory.Find(oldModel.categoryID);
     oldModel.qtyRemain = oldModel.qtyAvail;
     if (oldModel.tags == null)
     {
         oldModel.tags = "";
     }
     if (ModelState.IsValid)
     {
         productModel newModel = viewToModel(oldModel);
         newModel.sellerID   = User.Identity.GetUserId();
         newModel.dateListed = DateTime.Now;
         db.productmodel.Add(newModel);
         db.SaveChanges();
         if (newModel.images)
         {
             return(RedirectToAction("addPictures", "Product", new { productID = newModel.ID }));
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     else if (oldModel.productName == null && oldModel.city == null && oldModel.price == null)
     {
         return(View(oldModel));
     }
     else
     {
         return(View(oldModel));
     }
 }