public async Task <IActionResult> Photos(List <IFormFile> files) { var path = Path.Combine(environment.WebRootPath, "images"); StringBuilder builder = new StringBuilder(); int count = 0; foreach (var file in files) { if (file.Length > 0) { //var filename = Path.GetTempFileName(); using (var fs = new FileStream(Path.Combine(path, file.FileName), FileMode.Create)) { await file.CopyToAsync(fs); } builder.Append($"images/{file.FileName}").Append(";"); count++; } } var model = new ProductPhotoViewModel { PhotoPath = builder.ToString(), PhotoCount = count }; return(Ok(model)); }
public IEnumerable <ProductPhotoViewModel> GetProductPhotos(int Id) { string cs = ConfigurationManager.ConnectionStrings["EComMgt"].ConnectionString; List <ProductPhotoViewModel> productPhotos = new List <ProductPhotoViewModel>(); using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("getProductPhoto", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlParameter paramDetailsId = new SqlParameter(); paramDetailsId.ParameterName = "@DetailsId"; paramDetailsId.Value = Id; cmd.Parameters.Add(paramDetailsId); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { ProductPhotoViewModel productPhoto = new ProductPhotoViewModel(); if (!rdr.HasRows) { productPhoto.Id = Id; productPhoto.PhotoSrc = "pathToNoImage"; productPhoto.PhotoTitle = "No Image"; productPhotos.Add(productPhoto); } else { productPhoto.Id = Convert.ToInt32(rdr["Id"]); productPhoto.PhotoSrc = rdr["Src"].ToString(); productPhoto.PhotoPath = rdr["Path"].ToString(); productPhoto.PhotoTitle = rdr["Title"].ToString(); productPhotos.Add(productPhoto); } } } return(productPhotos); }
private void ProcessPhotos(ProductCreateOrEditViewModel model, Product target) { ProductPhotoViewModel mainPhotoViewModel = model.ProductPhotoViewModels.SingleOrDefault(x => x.IsMain); target.Photos.ForEach(photo => { photo.IsMain = mainPhotoViewModel != null && photo.Id == mainPhotoViewModel.Id; }); foreach (HttpPostedFileBase postedFile in model.PostedProductPhotos) { if (postedFile != null) { ProductPhoto photo = new ProductPhoto { Data = new byte[postedFile.InputStream.Length], ContentContentType = _contentContentTypesBL.Get(postedFile.ContentType), FileName = postedFile.FileName, IsMain = false }; postedFile.InputStream.Read(photo.Data, 0, photo.Data.Length); target.Photos.Add(photo); } } }
public IActionResult IgnoreThisEndpoint2([FromBody] ProductPhotoViewModel model) { return(Ok()); }