public async Task DoReact(ProductVMReactUI vm) { var product = new Product { ProductId = vm.ProductId, Name = vm.Name, Description = vm.Description, Stock = vm.Stock, Price = vm.Price, CategoryRefId = vm.CategoryRefId, }; if (vm.Photo != null) { product.Photo = await _fileManager.SaveImage(vm.Photo, "ProductPhoto"); } _context.Products.Add(product); await _context.SaveChangesAsync(); }
public async Task DoReact(ProductVMReactUI vm) { var product = _context.Products.FirstOrDefault(prod => prod.ProductId == vm.ProductId); product.Name = vm.Name; product.Description = vm.Description; product.Stock = vm.Stock; product.Price = vm.Price; product.CategoryRefId = vm.CategoryRefId; if (vm.Photo != null) { if (!string.IsNullOrEmpty(product.Photo)) { _fileManager.RemoveImage(product.Photo, "ProductPhoto"); } product.Photo = await _fileManager.SaveImage(vm.Photo, "ProductPhoto"); } _context.Products.Update(product); await _context.SaveChangesAsync(); }