public async Task <IActionResult> CreateParent(ParentCreateInputModel inputModel) { if (!ModelState.IsValid || !inputModel.Parent.StudentIds.Any()) { //ToDo: in case of null school/class, return appropriate message or add model validation? return(View(inputModel)); } try { var confirmViewModel = await _parentsService.CreateParentAsync <ConfirmCreatedViewModel>(inputModel.Parent); return(RedirectToAction(nameof(ConfirmCreated), confirmViewModel)); } catch (Exception e) { _logger.LogError(e, $"An exception occured during new parent record creation. Ex: {e.Message}"); return(RedirectToAction("Error", "Home")); } }
public async Task CreateParentAsync_WithoutAnyStudentIds() { OneTimeSetUp(); var parent = NewParentCreate(); var newParentInputModel = new ParentInputModel() { FirstName = parent.FirstName, LastName = parent.LastName, PhoneNumber = parent.PhoneNumber, StudentIds = new List <string> { } }; try { await _parentsService.CreateParentAsync <Parent>(newParentInputModel); } catch (ArgumentException ae) { ae.Message.Should().Be($"Sorry, we couldn't any student with id in the following list: [{string.Join(", ", newParentInputModel.StudentIds)}]"); } _parentsRepositoryMock.Object.All().Count().Should().Be(1); }