public ActionResult Create(Request request) { try { if (ViewData.ModelState.IsValid) { request.LastUpdateTimeStamp = DateTime.Now; request.LastUpdateUser = GetCurrentUser().Id; ActionConfirmation saveOrUpdateConfirmation = _requestManagementService.SaveOrUpdate(request); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; //return RedirectToAction("Index"); return RedirectToAction("Search"); } } else { request = null; } } catch (PreconditionException pce) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = pce.Message; } RequestFormViewModel viewModel = _requestManagementService.CreateFormViewModelFor(request); return View(viewModel); }
public void CanCompareRequests() { var instance = new Request(); instance.ShortDesc = "Request Short Desc"; var instanceToCompareTo = new Request(); instanceToCompareTo.ShortDesc = "Request Short Desc"; instance.ShouldEqual(instanceToCompareTo); }
public void CanDeleteRequest() { // Establish Context var requestToDelete = new Request(); _requestRepository.Expect(r => r.Get(1)) .Return(requestToDelete); // Act ActionConfirmation confirmation = _requestManagementService.Delete(1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldBeNull(); }
public void CanCreateValidRequestFromForm() { // Establish Context var requestFromForm = new Request(); var testUser = new Person(); testUser.SetAssignedIdTo(1); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1"); _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser); _requestManagementService.Expect(r => r.SaveOrUpdate(requestFromForm)) .Return(ActionConfirmation.CreateSuccessConfirmation("saved")); // Act RedirectToRouteResult redirectResult = _requestsController.Create(requestFromForm) .AssertActionRedirect().ToAction("Search"); // Assert _requestsController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString() .ShouldEqual("saved"); }
public RequestFormViewModel CreateFormViewModelFor(Request request) { var viewModel = new RequestFormViewModel { Request = request }; LoadViewModel(viewModel); return viewModel; }
private void TransferFormValuesTo(Request requestToUpdate, Request requestFromForm) { requestToUpdate.ShortDesc = requestFromForm.ShortDesc; requestToUpdate.LongDesc = requestFromForm.LongDesc; requestToUpdate.WorkPlanId = requestFromForm.WorkPlanId; requestToUpdate.CabPriority = requestFromForm.CabPriority; requestToUpdate.PhaseId = requestFromForm.PhaseId; requestToUpdate.BudgetedDollarAmount = requestFromForm.BudgetedDollarAmount; requestToUpdate.BudgetedDollarSpent = requestFromForm.BudgetedDollarSpent; requestToUpdate.BudgetLocationDeptId = requestFromForm.BudgetLocationDeptId; requestToUpdate.AllocatedHoursForIT = requestFromForm.AllocatedHoursForIT; requestToUpdate.AllocatedHoursForRequestor = requestFromForm.AllocatedHoursForRequestor; requestToUpdate.ActualHoursForRequestor = requestFromForm.ActualHoursForRequestor; requestToUpdate.IsRequestSignedOff = requestFromForm.IsRequestSignedOff; requestToUpdate.RequestDate = requestFromForm.RequestDate; requestToUpdate.RequestedStartDate = requestFromForm.RequestedStartDate; requestToUpdate.RevisedRequestedStartDate = requestFromForm.RevisedRequestedStartDate; requestToUpdate.RequestedEndDate = requestFromForm.RequestedEndDate; requestToUpdate.RevisedRequestedEndDate = requestFromForm.RevisedRequestedEndDate; requestToUpdate.ActualStartDate = requestFromForm.ActualStartDate; requestToUpdate.ActualEndDate = requestFromForm.ActualEndDate; requestToUpdate.DashboardId = requestFromForm.DashboardId; requestToUpdate.DashboardDescription = requestFromForm.DashboardDescription; requestToUpdate.PeriodUpdate = requestFromForm.PeriodUpdate; requestToUpdate.NextPeriodProjectedReport = requestFromForm.NextPeriodProjectedReport; requestToUpdate.KeyIssues = requestFromForm.KeyIssues; requestToUpdate.SupportMagicIdentifier = requestFromForm.SupportMagicIdentifier; requestToUpdate.SystemId = requestFromForm.SystemId; requestToUpdate.ProjectManagerId = requestFromForm.ProjectManagerId; requestToUpdate.StatusId = requestFromForm.StatusId; requestToUpdate.RequestTypeId = requestFromForm.RequestTypeId; requestToUpdate.ResponsibleOrgId = requestFromForm.ResponsibleOrgId; requestToUpdate.ExecutiveSponsorPersonId = requestFromForm.ExecutiveSponsorPersonId; requestToUpdate.UserLeadPersonId = requestFromForm.UserLeadPersonId; requestToUpdate.LastUpdateTimeStamp = requestFromForm.LastUpdateTimeStamp; requestToUpdate.LastUpdateUser = requestFromForm.LastUpdateUser; requestToUpdate.EstimatedHours = requestFromForm.EstimatedHours; requestToUpdate.Itgb = requestFromForm.Itgb; }
protected void ValidateRequest(Request request) { if (!string.IsNullOrEmpty(request.ShortDesc)) { Check.Require(_requestRepository.GetCount(request.ShortDesc, request.Id) == 0, "Request Short Description already exists"); } if (request.SystemId != null && request.SystemId.HasValue) { var wrmsSystem = _wrmsSystemManagementService.Get(request.SystemId.Value); Check.Require(wrmsSystem.IsActive == true, "The system you selected is inactive. Please select another."); } if (request.IsRequestSignedOff == null) request.IsRequestSignedOff = false; }
protected bool SaveEstimate(Request request) { //Get the Latest Estimate var latestEstimate = _requestEstimateManagementService.GetLatestByRequest(request.Id); if (latestEstimate == null || latestEstimate.EstimatedHours != request.EstimatedHours) { //Save the New Estimate var estimate = new RequestEstimate(); estimate.EstimatedHours = request.EstimatedHours; estimate.RequestId = request.Id; if (!_requestEstimateManagementService.SaveOrUpdate(estimate).WasSuccessful) { return false; } } return true; }
public ActionConfirmation UpdateWith(Request requestFromForm, int idOfRequestToUpdate) { Request requestToUpdate = _requestRepository.Get(idOfRequestToUpdate); ValidateRequest(requestFromForm); TransferFormValuesTo(requestToUpdate, requestFromForm); if (requestToUpdate.IsValid()) { if (!SaveEstimate(requestToUpdate)) { _requestRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The request could not be saved due to missing or invalid information."); } ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The request was successfully updated."); updateConfirmation.Value = requestToUpdate; return updateConfirmation; } else { _requestRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The request could not be saved due to missing or invalid information."); } }
public ActionConfirmation SaveOrUpdate(Request request) { if (request.IsValid()) { ValidateRequest(request); if (request.IsRequestSignedOff == null) { request.IsRequestSignedOff = false; } _requestRepository.SaveOrUpdate(request); if (!SaveEstimate(request)) { _requestRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The request could not be saved due to missing or invalid information."); } ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The request was successfully saved."); saveOrUpdateConfirmation.Value = request; return saveOrUpdateConfirmation; } else { _requestRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The request could not be saved due to missing or invalid information."); } }
public void CannotUpdateInvalidRequestFromForm() { // Establish Context var requestFromForm = new Request(); var viewModelToExpect = new RequestFormViewModel(); var testUser = new Person(); testUser.SetAssignedIdTo(1); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1"); _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser); _requestManagementService.Expect(r => r.UpdateWith(requestFromForm, 0)) .Return(ActionConfirmation.CreateFailureConfirmation("not updated")); _requestManagementService.Expect(r => r.CreateFormViewModelFor(requestFromForm)) .Return(viewModelToExpect); // Act ViewResult result = _requestsController.Edit(requestFromForm).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as RequestFormViewModel).ShouldNotBeNull(); }
public void CanUpdateWithValidRequestFromForm() { // Establish Context Request validRequestFromForm = RequestInstanceFactory.CreateValidTransientRequest(); // Intentionally empty to ensure successful transfer of values var requestFromDb = new Request(); _requestRepository.Expect(r => r.Get(1)) .Return(requestFromDb); WrmsSystem systemToExpect = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemManagementService.Expect(r => r.Get(13)) .Return(systemToExpect); _requestEstimateManagementService.Expect( r => r.SaveOrUpdate(new RequestEstimate { RequestId = validRequestFromForm.Id, EstimatedHours = validRequestFromForm.EstimatedHours })).Return( ActionConfirmation.CreateSuccessConfirmation("")); // Act ActionConfirmation confirmation = _requestManagementService.UpdateWith(validRequestFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(requestFromDb); confirmation.Value.ShouldEqual(validRequestFromForm); }
public void CannotUpdateWithInvalidRequestFromForm() { // Establish Context var invalidRequestFromForm = new Request(); // Intentionally empty to ensure successful transfer of values var requestFromDb = new Request(); _requestRepository.Expect(r => r.Get(1)) .Return(requestFromDb); // Act ActionConfirmation confirmation = _requestManagementService.UpdateWith(invalidRequestFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public void CannotSaveOrUpdateInvalidRequest() { // Establish Context var invalidRequest = new Request(); // Act ActionConfirmation confirmation = _requestManagementService.SaveOrUpdate(invalidRequest); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }