Exemple #1
0
		public AppraisalCompanyContactViewModel GetAppraisalCompanyContact(int appraisalCompanyId)
		{
			var appraisalCompany = _appraisalCompanyManagement.GetAppraisalCompanyById(appraisalCompanyId);

			var appraisalCompanyContact = new AppraisalCompanyContactViewModel();
			appraisalCompanyContact.PhysicalAddress = _addressManager.GetAddressViewModel<AddressViewModel>(null);
			appraisalCompanyContact.Phones = _phoneManager.GetPhonesViewModel(null);
			if (appraisalCompany.Contact != null)
			{
				appraisalCompanyContact.TextMsgNumber = appraisalCompany.Contact.TextMsgNumber;
				appraisalCompanyContact.PhysicalAddress = _addressManager.GetAddressViewModel<AddressViewModel>(appraisalCompany.Contact.PhysicalAddress);
				appraisalCompanyContact.Phones = _phoneManager.GetPhonesViewModel(appraisalCompany.Contact.Phones);
			}

			return appraisalCompanyContact;
		}
		public void contact_post_action_should_return_contact_view()
		{
			var viewContext = new ViewContext();
			viewContext.HttpContext = MockHttpContext.FakeHttpContext();
			IPrincipal user = new GenericPrincipal(new GenericIdentity("someUser"), null);
			viewContext.HttpContext.User.ReturnsForAnyArgs(user);

			AppraisalCompanyWizardService.GetAppraisalCompanyContact(Arg.Any<int>()).Returns(new AppraisalCompanyContactViewModel());
			AppraiserManagement.GetByEmail(Arg.Any<string>()).Returns(new AppraiserUser { Company = new AppraisalCompanyDetail() });
			var viewModel = new AppraisalCompanyContactViewModel();
			viewModel.PhysicalAddress = new AddressViewModel();
			Target.SetFakeControllerContext(viewContext.HttpContext);
			GeocodingValidation.ValidateAddress(Arg.Any<ValidateAddressArg>()).Returns(new ValidateAddressResult { IsValid = true });

			var actionResult = Target.Contact(viewModel, null);
			actionResult.Should().NotBeNull().And.BeOfType<RedirectToRouteResult>();
			((RedirectToRouteResult)actionResult).RouteValues.Should().HaveCount(1);
			((RedirectToRouteResult)actionResult).RouteValues["action"].Should().Be("Contact");
		}
		public void contact_should_redirect_to_contact_view_if_model_state_is_invalid()
		{
			AppraiserManagement.GetByEmail(Arg.Any<string>()).Returns(new AppraiserUser() { Company = new AppraisalCompanyDetail() });
			var viewModel = new AppraisalCompanyContactViewModel();
			viewModel.PhysicalAddress = new AddressViewModel();
			Target.ModelState.AddModelError("test error", "test error");
			GeocodingValidation.ValidateAddress(Arg.Any<ValidateAddressArg>()).Returns(new ValidateAddressResult { IsValid = true });

			var actionResult = Target.Contact(viewModel, null);
			actionResult.Should().NotBeNull().And.BeOfType<RedirectToRouteResult>();
			((RedirectToRouteResult)actionResult).RouteValues.Should().HaveCount(1);
			((RedirectToRouteResult)actionResult).RouteValues["action"].Should().Be("Contact");
		}
		public void contact_should_redirect_to_contact_view_if_model_state_is_invalid()
		{
			var viewModel = new AppraisalCompanyContactViewModel();
			Target.ModelState.AddModelError("test error", "test error");

			var actionResult = Target.Contact(viewModel, null);
			actionResult.Should().NotBeNull().And.BeOfType<RedirectToRouteResult>();
			((RedirectToRouteResult)actionResult).RouteValues.Should().HaveCount(1);
			((RedirectToRouteResult)actionResult).RouteValues["action"].Should().Be("Contact");
		}
		private ActionResult GetContactView(AppraisalCompanyContactViewModel appraisalCompanyContact)
		{
			ViewBag.CurrentStep = (int)TabSteps.Contact;
			return View(NameHelper.AppraisalCompanyDetails.Contact, appraisalCompanyContact);
		}
		public ActionResult Contact(int id, AppraisalCompanyContactViewModel appraisalCompanyContact, int? nextStep)
		{
			if (ModelState.IsValid)
			{
				var validateAddress = new ValidateAddressArg
				{
					City = appraisalCompanyContact.PhysicalAddress.City,
					State = appraisalCompanyContact.PhysicalAddress.State,
					Street = appraisalCompanyContact.PhysicalAddress.Street,
					ZIP = appraisalCompanyContact.PhysicalAddress.ZIP
				};
				var geocodingIsResolved = _geocodingValidation.ValidateAddress(validateAddress).IsValid;
				if (geocodingIsResolved)
				{
					_appraisalCompanyWizardService.SaveAppraisalCompanyContact(id, appraisalCompanyContact);
					CommitProviderInstance.Commit();
					return RedirectToStep(id, nextStep ?? (int)TabSteps.Contact);
				}
				TempData[GeocodingErrorMessageKey] = Constants.ErrorMessages.GeocodingVerificationError;
				TempData[AppraisalCompanyContactKey] = appraisalCompanyContact;
				return RedirectToAction(NameHelper.AppraisalCompanyDetails.Contact);
			}
			TempData[AppraisalCompanyContactKey] = appraisalCompanyContact;
			return RedirectToAction(NameHelper.AppraisalCompanyDetails.Contact);
		}
		public PartialViewResult AddEmptyPhone()
		{
			var phone = new PhoneItemViewModel { Id = Guid.NewGuid().ToString(), PhoneType = PhoneType.Mobile };
			var phonesViewModel = new PhonesViewModel { PhoneItems = new List<PhoneItemViewModel> { phone } };
			var model = new AppraisalCompanyContactViewModel { Phones = phonesViewModel };

			ViewBag.ExecuteBeginForm = true;
			ViewBag.ControllerName = CurrentControllerName;
			return PartialView("Tables/AppraisalCompanyPhones", model);
		}
		public ActionResult Contact(AppraisalCompanyContactViewModel appraisalCompanyContact, int? nextStep)
		{
			if (ModelState.IsValid)
			{
				var validateAddress = new ValidateAddressArg
				{
					City = appraisalCompanyContact.PhysicalAddress.City,
					State = appraisalCompanyContact.PhysicalAddress.State,
					Street = appraisalCompanyContact.PhysicalAddress.Street,
					ZIP = appraisalCompanyContact.PhysicalAddress.ZIP
				};
				var geocodingValidationResult = _geocodingValidation.ValidateAddress(validateAddress);
				if (!geocodingValidationResult.IsValid)
				{
					ViewBag.GeocodingErrorMessage = Constants.ErrorMessages.GeocodingVerificationError;
					return GetContactView(appraisalCompanyContact);
				}
				var appraisalCompanyId = GetAppraisalCompanyId();
				_appraisalCompanyWizardService.SaveAppraisalCompanyContact(appraisalCompanyId, appraisalCompanyContact);
				CommitProviderInstance.Commit();
				return RedirectToStep(nextStep);
			}

			TempData[AppraisalCompanyContactKey] = appraisalCompanyContact;
			return RedirectToAction(NameHelper.AppraisalCompanyProfile.Contact);
		}
		private ActionResult GetContactView(AppraisalCompanyContactViewModel appraisalCompanyContact)
		{
			ViewBag.CurrentStep = (int)TabIndex.Contact;
			CompanyWizzardMenuManager.RefreshContext();
			return View(NameHelper.AppraisalCompanyWizard.Contact, appraisalCompanyContact);
		}
		public ActionResult RemovePhone(AppraisalCompanyContactViewModel appraisalCompanyContact, string phoneId)
		{
			ModelState.Clear();
			var phoneItem = appraisalCompanyContact.Phones.PhoneItems.Single(pi => pi.Id == phoneId);
			appraisalCompanyContact.Phones.PhoneItems.Remove(phoneItem);

			TempData[_appraisalCompanyContactKey] = appraisalCompanyContact;
			return RedirectToAction(NameHelper.AppraisalCompanyWizard.Contact);
		}
		public ActionResult AddPhone(AppraisalCompanyContactViewModel appraisalCompanyContact)
		{
			ModelState.Clear();
			appraisalCompanyContact.Phones.PhoneItems.Add(new PhoneItemViewModel { Id = Guid.NewGuid().ToString(), PhoneType = PhoneType.Mobile });

			TempData[_appraisalCompanyContactKey] = appraisalCompanyContact;
			return RedirectToAction(NameHelper.AppraisalCompanyWizard.Contact);
		}
		public ActionResult Contact(AppraisalCompanyContactViewModel appraisalCompanyContact, int? nextStep, bool? isNextBanking = null, bool? preBankingPopupCompleted = null)
		{
			const int currentStep = (int)TabIndex.Contact;
			if ((nextStep ?? currentStep) <= currentStep || ModelState.IsValid)
			{
				var appraisalCompanyId = GetAppraisalCompanyId();
				//geocoding validation if next button is pressed
				if (nextStep != currentStep && !(preBankingPopupCompleted.HasValue && preBankingPopupCompleted.Value))
				{
					var validateAddress = new ValidateAddressArg
					{
						City = string.IsNullOrEmpty(appraisalCompanyContact.PhysicalAddress.City) ? string.Empty : appraisalCompanyContact.PhysicalAddress.City,
						State = string.IsNullOrEmpty(appraisalCompanyContact.PhysicalAddress.State) ? string.Empty : appraisalCompanyContact.PhysicalAddress.State,
						Street = string.IsNullOrEmpty(appraisalCompanyContact.PhysicalAddress.Street) ? string.Empty : appraisalCompanyContact.PhysicalAddress.Street,
						ZIP = string.IsNullOrEmpty(appraisalCompanyContact.PhysicalAddress.ZIP) ? string.Empty : appraisalCompanyContact.PhysicalAddress.ZIP
					};
					var geocodingValidationResult = _geocodingValidation.ValidateAddress(validateAddress);
					if (!geocodingValidationResult.IsValid)
					{
						ViewBag.ControllerName = CurrentControllerName;
						ViewBag.GeocodingErrorMessage = Constants.ErrorMessages.GeocodingVerificationError;
						return GetContactView(appraisalCompanyContact);
					}
				}
				_appraisalCompanyService.SaveAppraisalCompanyContact(appraisalCompanyId, appraisalCompanyContact);
				SaveLastCompletedStep(currentStep, nextStep);
				CommitProviderInstance.Commit();
				if (isNextBanking ?? false)
				{
					TempData["ShowPrebankingPopup"] = true;
					ViewBag.PreBankingAction = NameHelper.AppraisalCompanyWizard.Banking;
					ViewBag.PreBankingController = NameHelper.AppraisalCompanyWizard.Controller;

					return RedirectToStep((int)TabIndex.Contact);
				}
				if (!preBankingPopupCompleted.HasValue || !preBankingPopupCompleted.Value)
				{
					if (!nextStep.HasValue || nextStep.Value == currentStep)
					{
						TempData["SaveDraft"] = true;
					}
				}
				if (preBankingPopupCompleted.HasValue && preBankingPopupCompleted.Value)
				{
					nextStep = currentStep + 1;
				}
				if (!nextStep.HasValue || nextStep.Value > currentStep)
				{
					CompanyWizzardMenuManager.SetCompleteMenuIndex(currentStep);
				}
				return RedirectToStep(nextStep ?? currentStep);
			}

			ViewBag.ControllerName = CurrentControllerName;
			ViewBag.GeocodingErrorMessage = Constants.ErrorMessages.GeocodingVerificationError;
			return GetContactView(appraisalCompanyContact);
		}
Exemple #13
0
		public void SaveAppraisalCompanyContact(int appraisalCompanyId, AppraisalCompanyContactViewModel appraisalCompanyContact)
		{
			var appraisalCompany = _appraisalCompanyManagement.GetAppraisalCompanyById(appraisalCompanyId);

			if (appraisalCompany.Contact == null)
			{
				appraisalCompany.Contact = new AppraisalCompanyContact();
			}
			appraisalCompany.Contact.TextMsgNumber = appraisalCompanyContact.TextMsgNumber;
			if (appraisalCompany.Contact.PhysicalAddress == null)
			{
				appraisalCompany.Contact.PhysicalAddress = new Address();
			}
			_addressManager.FillAddress(appraisalCompany.Contact.PhysicalAddress, appraisalCompanyContact.PhysicalAddress);
			if (appraisalCompany.Contact.Phones == null)
			{
				appraisalCompany.Contact.Phones = new List<Phone>();
			}
			_phoneManager.FillPhones(appraisalCompany.Contact.Phones, appraisalCompanyContact.Phones);
		}