DocSas/PropertyService.Domain/ModelView/property/PropertyProvider.cs
/// <summary>
/// save property information as an asynchronous operation.
/// </summary>
/// <param name="propInfoVM">The property information vm.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
save property information as an asynchronous operation.
save property information as an asynchronous operation .
public async Task<DSCResponse> SavePropertyInfoAsync(PropertyInformationVM propInfoVM)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            PropertyInformation propInfo = null;
            var management = await _appCommon.GetManagementUserAsync(propInfoVM.UserId);
            if (management != null)
            {
                propInfoVM.AboutUs = Utility.HtmlEncode(propInfoVM.AboutUs);
                if (propInfoVM.Id != Guid.Empty)
                {
                    propInfo = await _propertyRepo.GetSingleAsync(x => x.Id == propInfoVM.Id, "ZipCode");
                    if (propInfo != null && management.Id == propInfo.ManagementUserId)
                    {
                        propInfo.PropName = propInfoVM.PropName;
                        propInfo.CoverOriginal = propInfoVM.CoverOriginal;
                        propInfo.CoverThumbnail = propInfoVM.CoverThumbnail;
                        propInfo.PropType = propInfoVM.PropType;
                        propInfo.StreetOne = propInfoVM.StreetOne;
                        propInfo.StreetTwo = propInfoVM.StreetTwo;
                        propInfo.Email = propInfoVM.Email;
                        propInfo.Phone = propInfoVM.Phone;
                        propInfo.Fax = propInfoVM.Fax;
                        propInfo.Weburl = propInfoVM.Weburl;
                        propInfo.AboutUs = propInfoVM.AboutUs;
                    }
                }
                else
                {
                    propInfo = _mapper.Map<PropertyInformationVM, PropertyInformation>(propInfoVM);
                    propInfo.UrlFriendlyName = CreateUrlFriendlyPropertyName(propInfo);
                    var property = await _propertyRepo.GetSingleAsync(x => x.UrlFriendlyName.Equals(propInfo.UrlFriendlyName), navigationPath: "ZipCode");
                    if (property != null)
                    {
                        msg.Add("PropertyAlreadyExists", "Property already exists");
                        response.ErrorMessage = msg;
                        return response;
                    }
                    propInfo.ManagementUserId = management.Id;
                }
                var zip = propInfo.ZipCode;
                if (zip != null)
                {
                    if (zip.Id != Guid.Empty)
                    {
                        var zipEntity = await _zipCodeRepo.GetSingleAsync(x => x.Id == zip.Id);
                        if (zipEntity != null)
                        {
                            if ((!string.IsNullOrWhiteSpace(zip.County) && string.IsNullOrWhiteSpace(zipEntity.County)))
                            {
                                zipEntity.County = zip.County;
                                await _zipCodeRepo.ModifyAsync(zipEntity);
                            }
                        }
                        propInfo.ZipId = zip.Id;
                        propInfo.ZipCode = null;
                    }
                    else if (propInfoVM.Id != Guid.Empty)
                    {
                        await _zipCodeRepo.AddAsync(zip);
                        propInfo.ZipId = zip.Id;
                        propInfo.ZipCode = null;
                    }
                }
                if (propInfoVM.Id == Guid.Empty)
                {
                    var code = await _codeGeneratorProvider.GenerateCodeAsync(DSCCodeType.Property);
                    if (code.IsSuccess)
                    {
                        propInfo.IsValid = true;
                        propInfo.PropCode = code.ResponseData.ToString();
                    }
                    await _propertyRepo.AddAsync(propInfo);
                }
                else
                {
                    propInfo.ZipCode = zip;
                    await _propertyRepo.ModifyAsync(propInfo);
                }
                if (propInfo.ZipCode == null)
                {
                    propInfo.ZipCode = zip;
                }
                var result = _mapper.Map<PropertyInformation, PropertyInformationVM>(propInfo);
                response.ResponseData = result;
            }
            return response;
        }
public async Task < DSCResponse > SavePropertyInfoAsync ( PropertyInformationVM propInfoVM ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; PropertyInformation propInfo = null ; var management = await _appCommon . GetManagementUserAsync ( propInfoVM . UserId ) ; if ( management != null ) { propInfoVM . AboutUs = Utility . HtmlEncode ( propInfoVM . AboutUs ) ; if ( propInfoVM . Id != Guid . Empty ) { propInfo = await _propertyRepo . GetSingleAsync ( x => x . Id == propInfoVM . Id , " " ) ; if ( propInfo != null && management . Id == propInfo . ManagementUserId ) { propInfo . PropName = propInfoVM . PropName ; propInfo . CoverOriginal = propInfoVM . CoverOriginal ; propInfo . CoverThumbnail = propInfoVM . CoverThumbnail ; propInfo . PropType = propInfoVM . PropType ; propInfo . StreetOne = propInfoVM . StreetOne ; propInfo . StreetTwo = propInfoVM . StreetTwo ; propInfo . Email = propInfoVM . Email ; propInfo . Phone = propInfoVM . Phone ; propInfo . Fax = propInfoVM . Fax ; propInfo . Weburl = propInfoVM . Weburl ; propInfo . AboutUs = propInfoVM . AboutUs ; } } else { propInfo = _mapper . Map < PropertyInformationVM , PropertyInformation > ( propInfoVM ) ; propInfo . UrlFriendlyName = CreateUrlFriendlyPropertyName ( propInfo ) ; var property = await _propertyRepo . GetSingleAsync ( x => x . UrlFriendlyName . Equals ( propInfo . UrlFriendlyName ) , navigationPath : " " ) ; if ( property != null ) { msg . Add ( " " , " " ) ; response . ErrorMessage = msg ; return response ; } propInfo . ManagementUserId = management . Id ; } var zip = propInfo . ZipCode ; if ( zip != null ) { if ( zip . Id != Guid . Empty ) { var zipEntity = await _zipCodeRepo . GetSingleAsync ( x => x . Id == zip . Id ) ; if ( zipEntity != null ) { if ( ( ! string . IsNullOrWhiteSpace ( zip . County ) && string . IsNullOrWhiteSpace ( zipEntity . County ) ) ) { zipEntity . County = zip . County ; await _zipCodeRepo . ModifyAsync ( zipEntity ) ; } } propInfo . ZipId = zip . Id ; propInfo . ZipCode = null ; } else if ( propInfoVM . Id != Guid . Empty ) { await _zipCodeRepo . AddAsync ( zip ) ; propInfo . ZipId = zip . Id ; propInfo . ZipCode = null ; } } if ( propInfoVM . Id == Guid . Empty ) { var code = await _codeGeneratorProvider . GenerateCodeAsync ( DSCCodeType . Property ) ; if ( code . IsSuccess ) { propInfo . IsValid = true ; propInfo . PropCode = code . ResponseData . ToString ( ) ; } await _propertyRepo . AddAsync ( propInfo ) ; } else { propInfo . ZipCode = zip ; await _propertyRepo . ModifyAsync ( propInfo ) ; } if ( propInfo . ZipCode == null ) { propInfo . ZipCode = zip ; } var result = _mapper . Map < PropertyInformation , PropertyInformationVM > ( propInfo ) ; response . ResponseData = result ; } return response ; }
save property information as an asynchronous operation.
save property information as an asynchronous operation .
None
propInfoVM
PropertyInformationVM
The property information vm.
The property information vm .