public async Task <int> AddArtistTypeAsync(AddArtistTypeBindingModel model) { var existingType = this.DbContext .ArtistTypes .FirstOrDefault(x => x.ArtistTypeName == model.ArtistTypeName); if (existingType != null) { return(ErrorId); } var type = this.Mapper.Map <ArtistType>(model); await this.DbContext.ArtistTypes.AddAsync(type); await this.DbContext.SaveChangesAsync(); return(type.Id); }
public async Task <IActionResult> AddArtistType(AddArtistTypeBindingModel model) { if (!this.ModelState.IsValid) { SetErrorMessage(CommonConstants.DangerMessage); return(this.AddArtistType()); } int generatedId = await this.artistService.AddArtistTypeAsync(model); if (generatedId < 1) { SetErrorMessage(CommonConstants.DuplicateMessage); return(this.AddArtistType()); } SetSuccessMessage(string.Format(CommonConstants.SuccessMessage, CommonConstants.ArtistTypeDisplay)); return(RedirectToAction(RedirectConstants.ArtistTypeDetailsSuffix, RedirectConstants.ArtistsSuffix, generatedId)); }