Example #1
0
		private void ChangeStatusOfBranches(AppraisalCompanyDetail companyDetail, AppraisalCompanyStatus newStatus, AppraisalCompanyStatus oldStatus)
		{
			var historyMapper = new CompanyStatusHistoryMapper();

			foreach (var branche in companyDetail.Branches)
			{
				if (branche.Status == AppraisalCompanyStatus.Inactive && newStatus == AppraisalCompanyStatus.Suspended)
				{
					continue;
				}

				var brancheNewStatus = newStatus;
				if (newStatus == AppraisalCompanyStatus.Active)
				{
					var historyForCompany = _trackingRepository.GetAppraisalCompanyStatusHistory(companyDetail.Id).FirstOrDefault(e => e.OldValue == AppraisalCompanyStatus.Active.ToString());
					if (historyForCompany != null)
					{
						var history = _trackingRepository.GetAppraisalCompanyBranchStatusHistory(branche.Id).ToArray();
						var lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date == historyForCompany.ChangeEntity.ChangeSet.Date);

						if (lastHistory == null)
						{
							lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date <= historyForCompany.ChangeEntity.ChangeSet.Date);
							if (lastHistory != null)
							{
								brancheNewStatus = historyMapper.Mapp(lastHistory.NewValue);
							}
						}
						else
						{
							brancheNewStatus = historyMapper.Mapp(lastHistory.OldValue);
						}
					}
				}
				branche.Status = brancheNewStatus;
				_appraisalBrancheChangeStatusNotification.StatusChanged(branche, branche.Status, oldStatus);
			}
		}
Example #2
0
		public void StatusChanged(AppraisalCompanyBranch companyBranch, AppraisalCompanyStatus newStatus,
															AppraisalCompanyStatus oldStatus)
		{
			var statusMapper = new CompanyUserMapper();
			var historyMapper = new CompanyStatusHistoryMapper();

			foreach (var appraiserUser in _appraiserManagement.GetUsersForBranch(companyBranch.Id))
			{
				if (appraiserUser.User.Roles.Count != 1 || appraiserUser.User.Roles.First().RoleType != RoleType.Appraiser || appraiserUser.Status == AppraiserUserStatus.Applied)
					continue;
				if (appraiserUser.Status == AppraiserUserStatus.Inactive && newStatus == AppraisalCompanyStatus.Suspended)
					continue;

				var userStatus = statusMapper.ToUserStatus(newStatus);
				if (newStatus == AppraisalCompanyStatus.Active)
				{
					var historyForCompany = _trackingRepository.GetAppraisalCompanyBranchStatusHistory(companyBranch.Id).FirstOrDefault(e => e.OldValue == AppraisalCompanyStatus.Active.ToString());
					if (historyForCompany != null)
					{
						var history = _trackingRepository.GetAppraiserStatusHistory(appraiserUser.User.Id).ToArray();
						var lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date == historyForCompany.ChangeEntity.ChangeSet.Date);

						if (lastHistory == null)
						{
							lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date <= historyForCompany.ChangeEntity.ChangeSet.Date);
							if (lastHistory != null)
							{
								userStatus = statusMapper.ToUserStatus(historyMapper.Mapp(lastHistory.NewValue));
							}
						}
						else
						{
							userStatus = statusMapper.ToUserStatus(historyMapper.Mapp(lastHistory.OldValue));
						}
					}
				}

				appraiserUser.Status = userStatus;
			}
		}
Example #3
0
		private void ChangeStatusOfAppraiserUsers(AppraisalCompanyDetail companyDetail, AppraisalCompanyStatus newStatus, AppraisalCompanyStatus oldStatus)
		{
			if (oldStatus == AppraisalCompanyStatus.Applied && newStatus == AppraisalCompanyStatus.Active)
				return;

			var userMapper = new CompanyUserMapper();
			var historyMapper = new CompanyStatusHistoryMapper();

			foreach (var appraiserUser in _appraiserManagement.GetUsersForCompany(companyDetail.Id))
			{
				if (appraiserUser.User.Roles.Any(e => e.RoleType != RoleType.Appraiser) || appraiserUser.Status == AppraiserUserStatus.Applied)
					continue;
				if (newStatus == AppraisalCompanyStatus.Suspended && appraiserUser.Status == AppraiserUserStatus.Inactive)
					continue;
                if ((newStatus == AppraisalCompanyStatus.Inactive || newStatus == AppraisalCompanyStatus.Suspended) && (appraiserUser.Status == AppraiserUserStatus.Applied))
                    continue;

				var appraiserUserStatus = userMapper.ToUserStatus(newStatus);
                
				if (newStatus == AppraisalCompanyStatus.Active)
				{
					var historyForCompany = _trackingRepository.GetAppraisalCompanyStatusHistory(companyDetail.Id).FirstOrDefault(e => e.OldValue == AppraisalCompanyStatus.Active.ToString());
					if (historyForCompany != null)
					{
						var history = _trackingRepository.GetAppraiserStatusHistory(appraiserUser.User.Id).ToArray();
						var lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date == historyForCompany.ChangeEntity.ChangeSet.Date);

						if (lastHistory == null)
						{
							lastHistory = history.FirstOrDefault(e => e.ChangeEntity.ChangeSet.Date <= historyForCompany.ChangeEntity.ChangeSet.Date);
							if (lastHistory != null)
							{
								appraiserUserStatus = userMapper.ToUserStatus(historyMapper.Mapp(lastHistory.NewValue));
							}
						}
						else
						{
							appraiserUserStatus = userMapper.ToUserStatus(historyMapper.Mapp(lastHistory.OldValue));
						}
					}
				}

				appraiserUser.Status = appraiserUserStatus;
			}
		}