Пример #1
0
        // NOTE: transaction has to implement or not , has to think more required.
        public AdDto CreateAd(AdDto dto)
        {
            #region Ad
            Share.Models.Ad.Entities.Ad ad = _mapper.Map <Share.Models.Ad.Entities.Ad>(dto);
            ad.UserPhoneNumber      = dto.UserPhoneNumber.ConvertToLongOrDefault();
            ad.UserPhoneCountryCode = dto.UserPhoneCountryCode.ConvertToShortOrDefault();
            int SRID = _configuration["SRID"].ConvertToInt();
            ad.AddressLocation = dto.IsValidLocation ? new Point(dto.Longitude, dto.Latitude)
            {
                SRID = SRID
            } : new Point(0.0, 0.0)
            {
                SRID = SRID
            };
            RepositoryResult result = _adRepository.Create(ad);
            if (!result.Succeeded)
            {
                throw new Exception(string.Join(Path.PathSeparator, result.Errors));
            }
            #endregion

            #region Google
            string content = _fileReadService.ReadFile(_configuration["FolderPathForGoogleHtmlTemplate"]);
            content = content.ToParseLiquidRender(dto);
            Stream stream  = new MemoryStream(Encoding.UTF8.GetBytes(content));
            string Dothtml = Path.GetExtension(_configuration["FolderPathForGoogleHtmlTemplate"]);

            var bucketName  = _configuration["AdBucketNameInGoogleCloudStorage"];
            var objectName  = string.Format("{0}{1}", dto.AttachedAssetsInCloudStorageId.Value, Dothtml);
            var contentType = Utility.GetMimeTypes()[Dothtml];
            _googleStorage.UploadObject(bucketName, stream, objectName, contentType);
            #endregion

            return(dto);
        }
Пример #2
0
        public List <Country> GetCountries()
        {
            List <Country> countries = _cacheService.Get <List <Country> >(nameof(GetCountries));

            if (countries == null)
            {
                string    json        = _fileReadService.ReadFile(_configuration["FolderPathForCountryJson"]);
                Countries jsonCountry = JsonConvert.DeserializeObject <Countries>(json);
                jsonCountry = _cacheService.GetOrAdd <Countries>(nameof(GetCountries), () => jsonCountry, _configuration["CacheExpireDays"].ConvertToCacheExpireDateTime());
                if (jsonCountry == null)
                {
                    throw new Exception(nameof(jsonCountry.Country));
                }
                countries = jsonCountry.Country;
            }
            return(countries);
        }