public void CreateProduct(ProductModel productModel) { var product = new Product(); product.Name = productModel.Name; product.Description = productModel.Description; product.Price = productModel.Price; product.ImageLocation = productModel.ImageLocation; product.CreatedDate = DateTime.UtcNow; FastFoodDbEntitiesInstance.Products.Add(product); FastFoodDbEntitiesInstance.SaveChanges(); //Save image in folder }
public ActionResult Create(ProductModel productModel, HttpPostedFileBase fileUpload) { Stream stream = null; var fileName = ""; var fullPictureName = ""; string pictureNamePrefix = Guid.NewGuid().ToString(); fileName = Path.GetFileName(fileUpload.FileName); fullPictureName = pictureNamePrefix + "_" + fileName; productModel.ImageLocation = fullPictureName; stream = fileUpload.InputStream; var fileBinary = new byte[stream.Length]; stream.Read(fileBinary, 0, fileBinary.Length); ProductData.CreateProduct(productModel); PictureHandler.SavePictureInFile(fileBinary, fullPictureName); return View(); }