public async Task <IActionResult> Update(BrandFormModel model) { var dbModel = Mapper.Map <Brand>(model); var successfulEditing = await this.adminBrandsService.UpdateAsync(dbModel); if (!successfulEditing) { ModelState.AddModelError(WebConstants.StatusMessage, WebConstants.BrandNameExists); return(View(model)); } TempData.AddSuccessMessage($"Brand {model.Name} successfully updated."); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(int id, BrandFormModel model) { var brandExists = await this.brandService.ExistsAsync(id); if (!brandExists) { this.TempData.AddErrorMessage(WebAdminConstants.BrandNotFoundMsg); return(RedirectToAction(nameof(Index))); } if (!this.ModelState.IsValid) { return(this.View(model)); } this.TempData.AddSuccessMessage(string.Format(WebAdminConstants.BrandUpdatedMsg, model.Name.ToStrongHtml())); return(this.RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(BrandFormModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } bool exists = await this.brandService.ExistsStringAsync(model.Name); if (!exists) { await this.brandService.CreateAsync(model.Name, model.Description); this.TempData.AddSuccessMessage(string.Format(WebAdminConstants.BrandCreatedMsg, model.Name.ToStrongHtml())); return(this.RedirectToAction(nameof(Index))); } this.TempData.AddErrorMessage(WebAdminConstants.BrandExists); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(BrandFormModel model) { var dbModel = Mapper.Map <Brand>(model); var userId = this.userManager.GetUserId(User); dbModel.AdminId = userId; dbModel.DateOfAddition = DateTime.UtcNow; var successfulCreation = await this.adminBrandsService.CreateAsync(dbModel); if (!successfulCreation) { ModelState.AddModelError(WebConstants.StatusMessage, WebConstants.BrandNameExists); return(View(model)); } TempData.AddSuccessMessage($"Brand {model.Name} successfully created."); return(RedirectToAction(nameof(Index))); }