DocSas/PropertyService.Domain/ModelView/property/Tenants/ResidentProvider.cs
/// <summary>
/// change resident status as an asynchronous operation.
/// </summary>
/// <param name="residencyStatus">The residency status.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
change resident status as an asynchronous operation.
change resident status as an asynchronous operation .
public async Task<DSCResponse> ChangeResidentStatusAsync(ResidencyStatusVM residencyStatus)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            var isSuccess = false;
            var tenant = await _tenantUnitRepo.GetSingleAsync(x => x.Id == residencyStatus.Id);
            if (tenant != null && tenant.PropertyInformationId == residencyStatus.PropertyInformationId && tenant.UserId == residencyStatus.ResidentUserId)
            {
                NotificationVM notification = new NotificationVM()
                {
                    UserId = tenant.UserId,
                    PropertyInformationId = tenant.PropertyInformationId,
                    NotificationTypeEnum = PSNotificationType.Residents.ToString(),
                    NotificationShowFor = tenant.UserId == residencyStatus.ChangerUserId ? PSNotificationShowFor.Property.ToString() : PSNotificationShowFor.User.ToString(),
                    NotificationTypeId = tenant.Id,
                    NotificationAdditionalInfo = tenant.UnitAddress
                };
                if (tenant.UserId != residencyStatus.ChangerUserId)
                {
                    notification.NotifeeUserId = tenant.UserId;
                }
                if (residencyStatus.StatusType == PSResidencyChangeType.MoveOut)
                {
                    notification.NotificationResourceKey = NotificationResourceKeys.NotifyInitiatedAMoveout;
                    tenant.IsMovedOut = residencyStatus.ChangeValue;
                }
                else if (residencyStatus.StatusType == PSResidencyChangeType.Approval && residencyStatus.ChangeValue)
                {
                    notification.NotificationResourceKey = NotificationResourceKeys.NotifyApprovedResidency;
                    tenant.IsApproved = residencyStatus.ChangeValue;
                }
                else if (residencyStatus.StatusType == PSResidencyChangeType.Cancel || (residencyStatus.StatusType == PSResidencyChangeType.Approval && !residencyStatus.ChangeValue))
                {
                    if (residencyStatus.StatusType == PSResidencyChangeType.Cancel)
                    {
                        notification.NotificationResourceKey = NotificationResourceKeys.NotifyCancelledResidency;
                    }
                    else
                    {
                        notification.NotificationResourceKey = NotificationResourceKeys.NotifyDeniedResidency;
                    }
                    isSuccess = await _tenantUnitRepo.DeleteAsync(tenant);
                }
                if (residencyStatus.StatusType == PSResidencyChangeType.MoveOut || (residencyStatus.StatusType == PSResidencyChangeType.Approval && residencyStatus.ChangeValue))
                {
                    isSuccess = await _tenantUnitRepo.ModifyAsync(tenant);
                }
                await _appCommon.AddNotification(notification);
            }
            response.ResponseData = isSuccess;
            return response;
        }
public async Task < DSCResponse > ChangeResidentStatusAsync ( ResidencyStatusVM residencyStatus ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; var isSuccess = false ; var tenant = await _tenantUnitRepo . GetSingleAsync ( x => x . Id == residencyStatus . Id ) ; if ( tenant != null && tenant . PropertyInformationId == residencyStatus . PropertyInformationId && tenant . UserId == residencyStatus . ResidentUserId ) { NotificationVM notification = new NotificationVM ( ) { UserId = tenant . UserId , PropertyInformationId = tenant . PropertyInformationId , NotificationTypeEnum = PSNotificationType . Residents . ToString ( ) , NotificationShowFor = tenant . UserId == residencyStatus . ChangerUserId ? PSNotificationShowFor . Property . ToString ( ) : PSNotificationShowFor . User . ToString ( ) , NotificationTypeId = tenant . Id , NotificationAdditionalInfo = tenant . UnitAddress } ; if ( tenant . UserId != residencyStatus . ChangerUserId ) { notification . NotifeeUserId = tenant . UserId ; } if ( residencyStatus . StatusType == PSResidencyChangeType . MoveOut ) { notification . NotificationResourceKey = NotificationResourceKeys . NotifyInitiatedAMoveout ; tenant . IsMovedOut = residencyStatus . ChangeValue ; } else if ( residencyStatus . StatusType == PSResidencyChangeType . Approval && residencyStatus . ChangeValue ) { notification . NotificationResourceKey = NotificationResourceKeys . NotifyApprovedResidency ; tenant . IsApproved = residencyStatus . ChangeValue ; } else if ( residencyStatus . StatusType == PSResidencyChangeType . Cancel || ( residencyStatus . StatusType == PSResidencyChangeType . Approval && ! residencyStatus . ChangeValue ) ) { if ( residencyStatus . StatusType == PSResidencyChangeType . Cancel ) { notification . NotificationResourceKey = NotificationResourceKeys . NotifyCancelledResidency ; } else { notification . NotificationResourceKey = NotificationResourceKeys . NotifyDeniedResidency ; } isSuccess = await _tenantUnitRepo . DeleteAsync ( tenant ) ; } if ( residencyStatus . StatusType == PSResidencyChangeType . MoveOut || ( residencyStatus . StatusType == PSResidencyChangeType . Approval && residencyStatus . ChangeValue ) ) { isSuccess = await _tenantUnitRepo . ModifyAsync ( tenant ) ; } await _appCommon . AddNotification ( notification ) ; } response . ResponseData = isSuccess ; return response ; }
change resident status as an asynchronous operation.
change resident status as an asynchronous operation .
None
residencyStatus
ResidencyStatusVM
The residency status.
The residency status .