public async Task <IActionResult> SellerEntry(ProductEntryVM _product) { IFormFile file = _product.ImagePath; //ImgUploader img = new ImgUploader(environment); string imgPath; string email = HttpContext.User.Identity.Name; var seller = await _context.Sellers .SingleOrDefaultAsync(m => m.Email == "*****@*****.**"); if (file == null || file.Length == 0) { return(Content("file not selected")); } var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot/images", file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } imgPath = $"/images/{file.FileName}"; try { if (_product != null) { var product = new Product { Title = _product.Title, Price = _product.Price, Description = _product.Description, PlaceId = _product.PlaceId, CategoryId = _product.CategoryId, ItemInStock = _product.ItemInStock, ImagePath = imgPath, SellerId = seller.Id, Unit = _product.Unit }; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (Exception) { throw; } return(View()); }
public void ProductEntry([FromBody] ProductEntryVM productEntryVM) { UnitOfWork.ProductRepository.Update((Product)productEntryVM); }