Exemplo n.º 1
0
        public ActionResult Edit(Agency agency)
        {
            try
            {
                if (ViewData.ModelState.IsValid)
                {
                    agency.LastUpdateTimeStamp = DateTime.Now;
                    agency.LastUpdateUser      = GetCurrentUser().Id;
                    ActionConfirmation updateConfirmation =
                        _agencyManagementService.UpdateWith(agency, agency.Id);

                    if (updateConfirmation.WasSuccessful)
                    {
                        TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                            updateConfirmation.Message;
                        return(RedirectToAction("Search"));
                    }
                }
            }
            catch (PreconditionException pce)
            {
                TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                    pce.Message;
            }

            AgencyFormViewModel viewModel =
                _agencyManagementService.CreateFormViewModelFor(agency);

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public void CanUpdateWithValidAgencyFromForm()
        {
            // Establish Context
            Agency validAgencyFromForm =
                AgencyInstanceFactory.CreateValidTransientAgency();

            // Intentionally empty to ensure successful transfer of values
            var agencyFromDb = new Agency();

            _agencyRepository.Expect(r => r.Get(1))
            .Return(agencyFromDb);

            // Act
            ActionConfirmation confirmation =
                _agencyManagementService.UpdateWith(validAgencyFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(agencyFromDb);
            confirmation.Value.ShouldEqual(validAgencyFromForm);
        }