public async Task <int> AddBrandTypeAsync(BrandTypeBindingModel model) { var existingType = this.DbContext .BrandTypes .FirstOrDefault(x => x.TypeName == model.TypeName); if (existingType != null) { return(ErrorId); } var type = this.Mapper.Map <BrandType>(model); await this.DbContext.BrandTypes.AddAsync(type); await this.DbContext.SaveChangesAsync(); return(type.Id); }
public async Task <IActionResult> AddBrandType(BrandTypeBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.View()); } int generatedId = await this.brandService.AddBrandTypeAsync(model); if (generatedId < 1) { SetErrorMessage(CommonConstants.DuplicateMessage); return(this.View()); } SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.BrandTypeDisplay)); return(RedirectToAction(RedirectConstants.BrandTypeBrandsSuffix, RedirectConstants.BrandsSuffix, generatedId)); }