public async Task DoReact(CategoryVMReactUI vm) { var category = new Category { CategoryId = vm.CategoryId, Name = vm.Name, }; if (vm.Photo != null) { category.Photo = await _fileManager.SaveImage(vm.Photo, "CategoryPhoto"); } _context.Categories.Add(category); await _context.SaveChangesAsync(); }
public async Task DoReact(CategoryVMReactUI vm) { var category = _context.Categories.FirstOrDefault(categ => categ.CategoryId == vm.CategoryId); category.Name = vm.Name; if (vm.Photo != null) { if (!string.IsNullOrEmpty(category.Photo)) { _fileManager.RemoveImage(category.Photo, "CategoryPhoto"); } category.Photo = await _fileManager.SaveImage(vm.Photo, "CategoryPhoto"); } _context.Categories.Update(category); await _context.SaveChangesAsync(); }