コード例 #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 AdDto UpdateAd(AdDto adDto)
        {
            Share.Models.Ad.Entities.Ad adExisting = _adRepository.Entities.Single(a => a.AdId == Convert.ToInt64(adDto.AdId));
            adExisting = _mapper.Map <AdDto, Share.Models.Ad.Entities.Ad>(adDto, adExisting);
            int   i        = _adRepository.SaveChanges();
            AdDto adDtoNew = _mapper.Map <AdDto>(adExisting);

            return(adDtoNew);
        }
コード例 #3
0
 public AdDto CreateAd(AdDto dto)
 {
     // transaction has to implement or not , has to think more required.
     Share.Models.Ad.Entities.Ad ad = this.InsertAd(dto);
     dto.GoogleStorageAdFileDto.AdAnonymousDataObjectForHtmlTemplate = GetAdAsAnonymousObjectForHtmlTemplate(dto);
     this.UploadObjectInGoogleStorage(dto.GoogleStorageAdFileDto);
     dto.GoogleStorageAdFileDto = null;
     return(dto);
 }
コード例 #4
0
        private Share.Models.Ad.Entities.Ad InsertAd(AdDto dto)
        {
            Share.Models.Ad.Entities.Ad ad = _mapper.Map <Share.Models.Ad.Entities.Ad>(dto);
            ad.UserPhoneNumber      = Utility.GetLongNumberFromString(dto.UserPhoneNumber);
            ad.UserPhoneCountryCode = Utility.GetShortNumberFromString(dto.UserPhoneCountryCode);
            ad.AddressLocation      = Utility.CreatePoint(dto.AddressLongitude, dto.AddressLatitude);
            RepositoryResult result = _adRepository.Create(ad);

            if (!result.Succeeded)
            {
                throw new Exception(string.Join(Path.PathSeparator, result.Errors));
            }
            return(ad);
        }