public async Task <IActionResult> ChangeStatus(AdminChangeApplicantsStatus model) { if (!ModelState.IsValid) { return(RedirectToAction(nameof(Index))); } try { await this.applicants.ChangeStatus(model); } catch (Exception e) { if (e.InnerException is InvalidOperationException) { return(RedirectToAction(nameof(ChangeStatus))); } throw e; } TempData.AddSuccessMessage(ChangeApplicantStatusMessage); return(RedirectToAction(nameof(Index))); }
public void ChangeStatus_WithValidStatus_ShouldCallService() { //Arrange var model = new AdminChangeApplicantsStatus(); bool serviceCalled = false; var mockRepository = new Mock <IAdminApplicantService>(); mockRepository.Setup(r => r.ChangeStatus(model)) .Callback(() => serviceCalled = true); var controller = new ApplicantsController(mockRepository.Object); //Act var result = controller.ChangeStatus(model); //Assert Assert.IsTrue(serviceCalled); }
public async Task ChangeStatus(AdminChangeApplicantsStatus model) { var applicant = await this.DbContext.Applicants.FirstOrDefaultAsync(a => a.Id == model.ApplicantId); var status = await this.DbContext.Statuses.FirstOrDefaultAsync(s => s.Id == model.StatusId); if (status == null || applicant == null) { throw new InvalidOperationException("Invalid Identity details."); } applicant.CurrentStatus = status.Id; applicant .Statuses .Add( new AplicantStatus { StatusId = status.Id, Time = DateTime.UtcNow }); await this.DbContext.SaveChangesAsync(); }