DocSas/PropertyService.Domain/ModelView/property/PropertyProvider.cs
/// <summary>
/// save tenant home as an asynchronous operation.
/// </summary>
/// <param name="tenantVM">The tenant vm.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
save tenant home as an asynchronous operation.
save tenant home as an asynchronous operation .
public async Task<DSCResponse> SaveTenantHomeAsync(TenantUnitVM tenantVM)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            var isSuccess = false;
            if (tenantVM.Id == Guid.Empty)
            {
                var property =  await _propertyRepo.GetSingleAsync(x => x.PropCode == tenantVM.PropertyCode && x.IsValid);
                if (property != null)
                {
                    var unit = await _tenantUnitRepo.GetSingleAsync(x => x.PropertyInformationId == property.Id && x.UserId == tenantVM.UserId  && !x.IsMovedOut);
                    if (unit != null)
                    {
                        msg.Add("HomeIsAlreadyAssinedToYou", "Home is taken");
                    }
                    else
                    {
                        var tenant = new TenantUnit()
                        {
                            PropertyInformationId =property.Id,
                            UserId = tenantVM.UserId,
                            UnitAddress = tenantVM.UnitAddress,
                            UnitName = tenantVM.UnitName
                        };
                        isSuccess =  await _tenantUnitRepo.AddAsync(tenant);
                        NotificationVM notification = new NotificationVM()
                        {
                            UserId = tenant.UserId,
                            PropertyInformationId = tenant.PropertyInformationId,
                            NotificationResourceKey = NotificationResourceKeys.NotifyNewResidentRequest,
                            NotificationTypeEnum = PSNotificationType.Residents.ToString(),
                            NotificationShowFor = PSNotificationShowFor.Property.ToString(),
                            NotificationTypeId = tenant.Id,
                            NotificationAdditionalInfo = tenant.UnitAddress
                        };
                        await _appCommon.AddNotification(notification);
                    }
                }
                else
                {
                    msg.Add("InvalidPropertyCode", "Invalid property code");
                }
            }
            else
            {
                var currentTenant = await _tenantUnitRepo.GetSingleAsync(x => x.Id == tenantVM.Id);
                if (currentTenant != null)
                {
                    currentTenant.UnitName = tenantVM.UnitName;
                   isSuccess =  await _tenantUnitRepo.ModifyAsync(currentTenant);
                }
            }
            response.ResponseData = isSuccess;
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > SaveTenantHomeAsync ( TenantUnitVM tenantVM ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; var isSuccess = false ; if ( tenantVM . Id == Guid . Empty ) { var property = await _propertyRepo . GetSingleAsync ( x => x . PropCode == tenantVM . PropertyCode && x . IsValid ) ; if ( property != null ) { var unit = await _tenantUnitRepo . GetSingleAsync ( x => x . PropertyInformationId == property . Id && x . UserId == tenantVM . UserId && ! x . IsMovedOut ) ; if ( unit != null ) { msg . Add ( " " , " " ) ; } else { var tenant = new TenantUnit ( ) { PropertyInformationId = property . Id , UserId = tenantVM . UserId , UnitAddress = tenantVM . UnitAddress , UnitName = tenantVM . UnitName } ; isSuccess = await _tenantUnitRepo . AddAsync ( tenant ) ; NotificationVM notification = new NotificationVM ( ) { UserId = tenant . UserId , PropertyInformationId = tenant . PropertyInformationId , NotificationResourceKey = NotificationResourceKeys . NotifyNewResidentRequest , NotificationTypeEnum = PSNotificationType . Residents . ToString ( ) , NotificationShowFor = PSNotificationShowFor . Property . ToString ( ) , NotificationTypeId = tenant . Id , NotificationAdditionalInfo = tenant . UnitAddress } ; await _appCommon . AddNotification ( notification ) ; } } else { msg . Add ( " " , " " ) ; } } else { var currentTenant = await _tenantUnitRepo . GetSingleAsync ( x => x . Id == tenantVM . Id ) ; if ( currentTenant != null ) { currentTenant . UnitName = tenantVM . UnitName ; isSuccess = await _tenantUnitRepo . ModifyAsync ( currentTenant ) ; } } response . ResponseData = isSuccess ; response . ErrorMessage = msg ; return response ; }
save tenant home as an asynchronous operation.
save tenant home as an asynchronous operation .
None
tenantVM
TenantUnitVM
The tenant vm.
The tenant vm .