public IActionResult EditCategory(int id, EditCategoryInputViewModel editCategoryInputViewModel) { var currCategory = this.ArtisticWorkService.GetCategoryById(id); if (currCategory == null) { return(RedirectToAction("Categories", "ArtisticWork", new { area = "" })); } this.ArtisticWorkService.EditCategory(id, editCategoryInputViewModel); return(RedirectToAction("Success", "Home", new { area = "" })); }
public void EditCategory(int CategoryId, EditCategoryInputViewModel editCategoryInputViewModel) { if (this.DbContext.ArtisticWorkCategories.Any(c => c.Id == CategoryId) && editCategoryInputViewModel.PictureNew != null) { var imgFileName = $"{Guid.NewGuid()}{GlobalConstants.JpegFileExtension}"; if (editCategoryInputViewModel.PictureNew != null) { var oldImageFileName = DbContext.ArtisticWorkCategories.First(c => c.Id == CategoryId).MainPictureFileName; if (File.Exists($"{GlobalConstants.ArtCategoriesDirectoryPath}{oldImageFileName}")) { File.Delete($"{GlobalConstants.ArtCategoriesDirectoryPath}{oldImageFileName}"); } var newImageFileName = this.FileService.UploadImageAsync(GlobalConstants.ArtCategoriesDirectoryPath, imgFileName, editCategoryInputViewModel.PictureNew).Result; DbContext.ArtisticWorkCategories.First(c => c.Id == CategoryId).MainPictureFileName = newImageFileName; DbContext.SaveChanges(); } } }
public async Task <IActionResult> UpdateAsync(int id, EditCategoryInputViewModel model) { await _categoryService.UpdateAsync(id, model.CategoryName); return(CreatedAtAction(nameof(GetAsync), new { id }, null)); }
public async Task <IActionResult> CreateAsync(EditCategoryInputViewModel input) { await _categoryService.CreateAsync(input.CategoryName); return(Ok()); }