public ActionResult UpdateProduct(ProductDetail pd, HttpPostedFileBase _ProductImage) { if (ModelState.IsValid) { Product prod = _unitOfWork.GetRepositoryInstance <Product>().GetFirstOrDefault(pd.ProductId); prod = prod != null ? prod : new Product(); prod.CategoryId = pd.CategoryId; prod.Description = pd.Description; prod.IsActive = pd.IsActive; prod.IsFeatured = pd.IsFeatured; prod.Price = pd.Price; prod.ProductImage = _ProductImage != null ? _ProductImage.FileName : prod.ProductImage; prod.ProductName = pd.ProductName; prod.ModifiedDate = DateTime.Now; if (prod.ProductId == 0) { prod.CreatedDate = DateTime.Now; prod.IsDelete = false; _unitOfWork.GetRepositoryInstance <Product>().Add(prod); } else { _unitOfWork.GetRepositoryInstance <Product>().Update(prod); _unitOfWork.SaveChanges(); } if (_ProductImage != null) { uc.UploadImage(_ProductImage, prod.ProductId + "_", "/Content/ProductImage/", Server, _unitOfWork, 0, prod.ProductId, 0); } return(RedirectToAction("Products")); } pd.Categories = new SelectList(_unitOfWork.GetRepositoryInstance <Category>().GetAllRecordsIQueryable(), "CategoryId", "CategoryName"); return(View("UpdateProduct", pd)); }
public ActionResult UpdateBrand(BrandDetail cd, HttpPostedFileBase _BrandImage) { int poz = 0; if (ModelState.IsValid) { Tbl_Brand b = _unitOfWork.GetRepositoryInstance <Tbl_Brand>().GetFirstOrDefault(cd.BrandId); b = b != null ? b : new Tbl_Brand(); b.BrandName = cd.BrandName; if (_BrandImage != null) { for (int i = _BrandImage.FileName.Length - 4; i >= 0; i--) { if (_BrandImage.FileName[i] == '\\') { poz = i; break; } } } b.BrandImage = _BrandImage != null?_BrandImage.FileName.Substring(poz + 1) : b.BrandImage; if (cd.BrandId != 0) { _unitOfWork.GetRepositoryInstance <Tbl_Brand>().Update(b); _unitOfWork.SaveChanges(); } else { b.IsActive = true; b.IsDelete = false; _unitOfWork.GetRepositoryInstance <Tbl_Brand>().Add(b); } return(RedirectToAction("Brands")); if (_BrandImage != null) { uc.UploadImage(_BrandImage, b.BrandId + "_", "/Content/ProductImage/", Server, _unitOfWork, 0, b.BrandId, 0); } return(RedirectToAction("Products")); } else { return(View("UpdateBrand", cd)); } }