public async Task <IActionResult> Index(SkillInputViewModel model) { if (!ModelState.IsValid) { return(this.View(model)); } int id = default(int); try { id = await this.skillService.SaveFormData(model, userName); } catch (Exception e) { this.logger.LogDebug(e, $"An exception happened for user {userName}"); return(this.BadRequest()); } return(this.Redirect(Url.RouteUrl(new { controller = "Resume", action = "Display" }) + $"#{id}")); }
public async Task <int> SaveFormData(SkillInputViewModel model, string userName) { if (string.IsNullOrWhiteSpace(userName)) { throw new NullReferenceException($"{userName} is null or empty"); } if (model == null) { throw new NullReferenceException("Skill model is null"); } if (this.resumeId == null) { throw new InvalidOperationException($"Resume id is null for user {userName}."); } var skill = new Skill { ResumeId = this.resumeId.Value, Name = this.sanitizer.Sanitize(model.Name), }; await this.skillRepo.AddAsync(skill); int id = default(int); try { await this.skillRepo.SaveChangesAsync(); id = skill.Id; } catch (Exception e) { throw new InvalidOperationException(e.Message); } return(id); }