public void InterestedPerson_ShouldBeInvalid() { var interestedPerson = new InterestedPerson { }; var errors = ValidateModel(interestedPerson); Assert.IsTrue(errors.Any()); }
public void InterestedPerson_ShouldBeValid() { var interestedPerson = new InterestedPerson { Email = "*****@*****.**", FirstName = "John", LastName = "Doe", ActivityType = ActivityType.Basketball }; var errors = ValidateModel(interestedPerson); Assert.IsFalse(errors.Any()); }
public async Task <IActionResult> Post([FromBody] InterestedPerson interestedPerson) { try { if (ModelState.IsValid) { await _interestedPersonRepository.AddInterestedPerson(interestedPerson); return(Ok()); } else { _logger.LogError("Error saving employee activity. Model in bad state."); return(BadRequest("Error saving employee activity.")); } } catch (Exception ex) { _logger.LogError(ex, "Exception thrown getting Interested Persons"); return(BadRequest(ex)); } }
public async Task AddInterestedPerson(InterestedPerson interestedPerson) { _context.Add(interestedPerson); await _context.SaveChangesAsync(); }