public ActionResult Create(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); if (product.ImageFile != null) { var folder = "~/Content/Products"; var file = string.Format("{0}-{1}.jpg", product.ProductId, product.Description); var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file); if (respose) { var pic = string.Format("{0}/{1}", folder, file); //si respose es true, actualizamos el logo de la compania product.Image = pic; //actalizamos la dv db.Entry(product).State = EntityState.Modified; db.SaveChanges(); } } return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
public ActionResult Edit(Product product) { if (ModelState.IsValid) { if (product.ImageFile != null) { var pic = string.Empty; var folder = "~/Content/Products"; var file = string.Format("{0}-{1}.jpg", product.ProductId, product.Description); var respose = FilesHelpers.UploadPhoto(product.ImageFile, folder, file); if (respose) { pic = string.Format("{0}/{1}", folder, file); product.Image = pic; } } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
public ActionResult Edit(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); byte[] imagenActual = null; HttpPostedFileBase FileBase = Request.Files[0]; if (FileBase == null) { imagenActual = db.Products.SingleOrDefault(t => t.ProductID == product.ProductID).Image; } else { WebImage image = new WebImage(FileBase.InputStream); product.Image = image.GetBytes(); } if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; var response = DBHelper.SaveChanges(db); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(product.CompanyID), "CategoryID", "Descripcion", product.CategoryID); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(product.CompanyID), "TaxID", "Description", product.TaxID); return(View(product)); }
public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(user.CompanyId), "CategoryId", "Description"); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(user.CompanyId), "TaxId", "Description"); var product = new Product { CompanyId = user.CompanyId }; return(View(product)); }
// GET: Products/Create public ActionResult Create() { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (user == null) { return(RedirectToAction("Index", "Home")); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(user.CompanyID), "CategoryID", "Descripcion"); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(user.CompanyID), "TaxID", "Description"); var product = new Product { CompanyID = user.CompanyID, }; return(View(product)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } ViewBag.CategoryId = new SelectList(CombosHelpers.GetCategories(product.CompanyId), "CategoryId", "Description", product.CategoryId); ViewBag.TaxId = new SelectList(CombosHelpers.GetTaxes(product.CompanyId), "TaxId", "Description", product.TaxId); return(View(product)); }
// GET: Products/Edit/5 public ActionResult Edit(int?id) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Product product = db.Products.Find(id); if (product == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(product.CompanyID), "CategoryID", "Descripcion", product.CategoryID); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(product.CompanyID), "TaxID", "Description", product.TaxID); return(View(product)); }
public ActionResult Create(Product product) { var user = db.Users.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); if (ModelState.IsValid) { HttpPostedFileBase FileBase = Request.Files[0]; WebImage image = new WebImage(FileBase.InputStream); product.Image = image.GetBytes(); db.Products.Add(product); var response = DBHelper.SaveChanges(db); if (response.Succeeded) { return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, response.Message); } ViewBag.CategoryID = new SelectList(CombosHelpers.GetCategories(user.CompanyID), "CategoryID", "Descripcion", product.CategoryID); ViewBag.TaxID = new SelectList(CombosHelpers.GetTaxes(user.CompanyID), "TaxID", "Description", product.TaxID); return(View(product)); }