//method to craete product public async Task <Response> Do(Request request) { //ToDo adding image(s) if (request.File != null) { string uploads = Path.Combine(_hosting.WebRootPath, @"images"); string fullPath = Path.Combine(uploads, request.File.FileName); request.File.CopyTo(new FileStream(fullPath, FileMode.Create)); } var product = new Product { Name = request.Name, Description = request.Description, Value = request.Value, ImgUrl = request.File.FileName, //Tooo CategoryId = request.CatagoryId, }; if (await _productManager.CreatProduct(product) <= 0) { throw new Exception("Faild To Creat Product"); } if (request.Files != null) { foreach (var img in request.Files) { string uploads = Path.Combine(_hosting.WebRootPath, @"gallery"); string fullPath = Path.Combine(uploads, img.FileName); img.CopyTo(new FileStream(fullPath, FileMode.Create)); var imgGallery = new ImgGallary { GallaryImgUrl = img.FileName, ProductId = product.Id }; await _productManager.UploadGallery(imgGallery); } } return(new Response { Id = product.Id, Name = product.Name, Description = product.Description, Value = product.Value, ImgUrl = product.ImgUrl, //Tooo CatagoryId = product.CategoryId }); }
public Task <int> UploadGallery(ImgGallary imgGallary) { _ctx.ProductImgGallary.Add(imgGallary); return(_ctx.SaveChangesAsync()); }