public async Task <ActionResult <EducationViewModel> > CreateEducation(EducationInputViewModel viewModel) { Education createdEducation = await EducationService.AddEducation(Mapper.Map <Education>(viewModel)); return(CreatedAtAction(nameof(GetEducation), new { id = createdEducation.Id }, Mapper.Map <EducationViewModel>(createdEducation))); }
public async Task <int> SaveFormData(EducationInputViewModel model, string userName) { if (string.IsNullOrWhiteSpace(userName)) { throw new NullReferenceException($"{userName} is null or empty"); } if (model == null) { throw new NullReferenceException("Education model is null"); } if (this.resumeId == null) { throw new InvalidOperationException($"Resume id is null for user {userName}."); } var education = new Education { ResumeId = this.resumeId.Value, Institution = this.sanitizer.Sanitize(model.Institution), StartDate = model.StartDate, EndDate = model.EndDate.HasValue ? model.EndDate.Value : (DateTime?)null, GPA = model.GPA, MainSubjects = this.sanitizer.Sanitize(model.MainSubjects), Diploma = this.sanitizer.Sanitize(model.Diploma), City = model.City, Country = model.Country, Region = model.Region }; await this.educationRepo.AddAsync(education); int id = default(int); try { await this.educationRepo.SaveChangesAsync(); id = education.Id; } catch (Exception e) { throw new InvalidOperationException(e.Message); } return(id); }
public async Task <IActionResult> Index(EducationInputViewModel model) { if (!ModelState.IsValid) { return(this.View(model)); } int id = default(int); try { id = await this.educationService.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}")); }