public async Task <IActionResult> Create(UseFullCategoryWithImageViewModel model) { if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName)) { return(this.Redirect("/Identity/Account/AccessDenied")); } if (this.ModelState.IsValid) { bool useFullCategoryExists = await this.useFullCategoryService.CheckIfExistsAsync(model.Name); if (useFullCategoryExists) { var existError = new UseFullCategoryError { ErrorMessage = GlobalConstants.UseFullCategoryExistErrorMessage }; return(this.RedirectToAction("Error", "UseFullCategory", existError)); } await this.useFullCategoryService.CreateUseFullCategoryByNameAsync(model.Name, model.ImageAddress); return(this.Redirect("/UseFullCategory/All")); } var error = new UseFullCategoryError { ErrorMessage = GlobalConstants.UseFullCategoryModelValidationMessаge }; return(this.RedirectToAction("Error", "UseFullCategory", error)); }
public List <UseFullCategoryWithImageViewModel> GetAllUseFullCategoriesWithParams() { var allUseFullCategories = this.useFullCategories.All(); List <UseFullCategoryWithImageViewModel> useFullCategoryWithImages = new List <UseFullCategoryWithImageViewModel>(); foreach (var item in allUseFullCategories) { UseFullCategoryWithImageViewModel viewModel = new UseFullCategoryWithImageViewModel { Name = item.Name, ImageAddress = item.ImageAddress, }; useFullCategoryWithImages.Add(viewModel); } return(useFullCategoryWithImages); }
public async Task <IActionResult> Create(UseFullCategoryWithImageViewModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/UseFullCategory/Create")); } else { bool useFullCategoryExists = this.useFullCategoryService.CheckIfExists(model.Name); if (useFullCategoryExists) { return(this.Redirect("/UseFullCategory/Create")); } else { await this.useFullCategoryService.CreateUseFullCategoryByNameAsync(model.Name, model.ImageAddress); return(this.Redirect("/UseFullCategory/All")); } } }