public ActionResult Edit(ProductCategoryRelation pcr, int id, HttpPostedFileBase file) { try { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("~/Images/" + fileName)); pcr.product.Picture = WebConfigurationManager.AppSettings["ImageUpload"] + fileName; } pcr.product.ProductId = id; pcr.categories = LetsShopImplementation.GetCategoryIdByName(pcr.categories.CategoryName, pcr.categories.SubCategoryName); pcr.product.CategoryId = pcr.categories.CategoryId; pcr.product.SubCategoryId = pcr.categories.SubCategoryId; LetsShopImplementation.UpdateProduct(pcr.product); cache.Add("ProductData", LetsShopImplementation.GetProducts(), CacheItemPriority.High, null, absolutetime); return RedirectToAction("Index"); } catch (Exception ex) { bool rethrow = ExceptionPolicy.HandleException(ex, "UI Policy"); if (rethrow) throw; return View(); } }
//_____________________________________________________________________ /// <summary> /// Gets the details of the particular product through its ProductId. /// </summary> /// <param name="productid"></param> /// <returns></returns> public static ProductCategoryRelation GetProduct(int productid) { ProductCategoryRelation pc = new ProductCategoryRelation(); Product prod = new Product(); Categories cat = new Categories(); prod.ProductId = productid; Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("LetsShopConnString"); DbCommand cmdObj = _db.GetStoredProcCommand("GetProductById"); _db.AddInParameter(cmdObj, "@ProductId", DbType.Int32, Convert.ToInt32(productid)); using (IDataReader dataReader = _db.ExecuteReader(cmdObj)) { while (dataReader.Read()) { prod.ProductId = Convert.ToInt32(dataReader["ProductId"]); prod.ProductName = dataReader["ProductName"].ToString(); prod.ProductDescription = dataReader["ProductDescription"].ToString(); prod.CategoryId = Convert.ToInt32(dataReader["CategoryId"]); prod.SubCategoryId = Convert.ToInt32(dataReader["SubCategoryId"]); prod.Price = Double.Parse(dataReader["Price"].ToString()); prod.UnitsInStock = Convert.ToInt32(dataReader["UnitsInStock"]); prod.StockAvailability = Convert.ToInt32(dataReader["StockAvailability"]); prod.Colour = dataReader["Colour"].ToString(); prod.Size = dataReader["Size"].ToString(); prod.Picture = dataReader["Picture"].ToString(); } } DbCommand cmdObj2 = _db.GetStoredProcCommand("GetCategoryNameById"); _db.AddInParameter(cmdObj2, "@CategoryId", DbType.Int32, Convert.ToInt32(prod.CategoryId)); _db.AddInParameter(cmdObj2, "@SubCategoryId", DbType.Int32, Convert.ToInt32(prod.SubCategoryId)); using (IDataReader dataReader = _db.ExecuteReader(cmdObj2)) { while (dataReader.Read()) { cat.CategoryName = dataReader["CategoryName"].ToString(); cat.SubCategoryName = dataReader["SubCategoryName"].ToString(); } } pc.product = prod; pc.categories = cat; return pc; }