Пример #1
0
        public AdDto GetAdDetail(long adId)
        {
            var   ad    = _adRepository.Entities.AsNoTracking().FirstOrDefault(i => i.AdId == adId);
            AdDto adDto = _mapper.Map <AdDto>(ad);

            return(adDto);
        }
Пример #2
0
        public static void Defaults(this AdDto model, IConfiguration _configuration)
        {
            byte adDefaultDisplayActiveDays;

            if (byte.TryParse(_configuration["AdDefaultDisplayActiveDays"], out adDefaultDisplayActiveDays))
            {
                model.AdDisplayDays = adDefaultDisplayActiveDays;
            }

            double Longitude;

            if (double.TryParse(_configuration["DefaultLongitude"], out Longitude))
            {
                model.AddressLongitude = "1.0";
            }

            double Lattitude;

            if (double.TryParse(_configuration["DefaultLattitude"], out Lattitude))
            {
                model.AddressLatitude = "1.0";
            }

            model.AdId = DateTime.UtcNow.Ticks.ToString();
            model.AttachedAssetsInCloudStorageId = Guid.NewGuid();
            model.CreatedDateTime = model.UpdatedDateTime = DateTime.UtcNow;
            model.IsDeleted       = model.IsActivated = model.IsPublished = false;
        }
Пример #3
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);
        }
Пример #4
0
 private dynamic GetAdAsAnonymousObjectForHtmlTemplate(AdDto dto)
 {
     return(new
     {
         activedays = dto.AdDisplayDays,
         adaddressatpublicsecuritynearlandmarkname = dto.AddressPartiesMeetingLandmark,
     });
 }
Пример #5
0
        public void AddNewAd(AdDto dto)
        {
            var ent = Ad.GetEnt(dto);

            ent.PostDate = DateTime.Now;
            context.Ads.Add(ent);
            context.SaveChanges();
        }
Пример #6
0
        public async Task <ActionResult> PutAd(string userid, string projectid, [FromBody] AdDto updatedAd)
        {
            if (!ExternalIdPassedGuidValidation(userid))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, $"Invalid {nameof(userid)}."));
            }

            if (!ExternalIdPassedGuidValidation(projectid))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, $"Invalid {nameof(projectid)}."));
            }

            bool userHaveAccessToProject;

            try
            {
                userHaveAccessToProject = await UserHaveAccessToProject(userid, projectid);
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex));
            }

            if (!userHaveAccessToProject)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Access to project ads denied."));
            }

            Ad ad;

            try
            {
                ad = await adsRepository.GetAdAsync(updatedAd.ExternalId);
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, ex.Message));
            }

            if (!ad.ExternalId.Equals(updatedAd.ExternalId) || !ad.ProjectExternalId.Equals(updatedAd.ProjectExternalId))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Updated ad external id or project id missmatch."));
            }

            try
            {
                ad.Name           = updatedAd.Name;
                ad.Url            = updatedAd.Url;
                ad.FileExternalId = updatedAd.FileExternalId;
                await adsRepository.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(Ok());
        }
Пример #7
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);
        }
Пример #8
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);
 }
Пример #9
0
        public IActionResult GetAdDetail(long adId)
        {
            if (adId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(adId));
            }
            AdDto dto = _adService.GetAdDetail(adId);

            return(Ok(dto));
        }
Пример #10
0
        public async Task <bool> Handle(AdCommand message)
        {
            AdDto dtoCreated = new AdDto()
            {
                Id    = message.Id,
                Title = message.Title
            };

            return(await _adService.CreateNewAd(dtoCreated));
        }
Пример #11
0
 public Ad ToAd(AdDto dto)
 {
     return(new Ad
     {
         Id = dto.Id,
         Title = dto.Title,
         Description = dto.Description,
         Price = dto.Price,
         Username = dto.Username
     });
 }
Пример #12
0
        public IActionResult UpdateAd([FromBody] AdDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AdDto adDto = _adService.UpdateAd(model);

            return(Ok(adDto));
        }
        public void getall_ads_given_valid_parameters()
        {
            //Arrange

            //Act
            AdDto ad = this.adQueryService.GetAdAndApplyDiscount("1234", DISCOUNT);

            //this.domainService.Verify(x => x.ApplyDiscount(this.ads, DISCOUNT), Times.Once);
            this.adQueryRepository.Verify(x => x.GetAll(), Times.Once);

            //Assert
            Assert.That(ads, Is.Not.Null);
        }
Пример #14
0
        public async Task <IActionResult> Post([FromBody] AdDto ad)
        {
            try
            {
                await _adService.AddAsync(ad);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #15
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);
        }
Пример #16
0
        public static KeyValuePair <bool, string> IsValidCreateAdInputs(this AdDto dto, IConfiguration _configuration, IJsonDataService _jsonDataService)
        {
            List <string> errors = new List <string>();

            dto.AdId          = DateTime.UtcNow.Ticks.ToString();
            dto.AdDisplayDays = _configuration["AdDefaultDisplayActiveDays"].ConvertToByte();
            dto.AttachedAssetsInCloudStorageId = Guid.NewGuid();
            dto.CreatedDateTime = dto.UpdatedDateTime = DateTime.UtcNow;
            dto.IsDeleted       = false;
            dto.IsActivated     = dto.IsPublished = true;

            if (string.IsNullOrWhiteSpace(_configuration["FolderPathForGoogleHtmlTemplate"]))
            {
                errors.Add("FolderPathForGoogleHtmlTemplate");
            }
            if (string.IsNullOrWhiteSpace(_configuration["AdBucketNameInGoogleCloudStorage"]))
            {
                errors.Add("AdBucketNameInGoogleCloudStorage");
            }
            if (string.IsNullOrWhiteSpace(_configuration["CacheExpireDays"]))
            {
                errors.Add("CacheExpireDays");
            }

            if (!_jsonDataService.IsValidCategory(dto.AdCategoryId))
            {
                errors.Add(nameof(dto.AdCategoryId));
            }
            if (!_jsonDataService.IsValidCategory(dto.ItemConditionId))
            {
                errors.Add(nameof(dto.ItemConditionId));
            }
            //if (!_jsonDataService.IsValidCallingCode(int.Parse(dto.UserPhoneCountryCode)))
            //    errors.Add(nameof(dto.UserPhoneCountryCode));

            if (dto.AddressLongitude.IsValidLocation(dto.AddressLatitude))
            {
                dto.IsValidLocation = true;
            }
            if (dto.IsValidLocation)
            {
                dto.Longitude = dto.AddressLongitude.ConvertToDouble();
                dto.Latitude  = dto.AddressLatitude.ConvertToDouble();
            }

            return(new KeyValuePair <bool, string>(errors.Count > 0, string.Join(Path.PathSeparator, errors)));
        }
Пример #17
0
        // this function may not work with dynamic
        //Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
        public static string ToParseLiquidRender(this string html, AdDto dto)
        {
            var anonymousDataObject = new
            {
                activedays = dto.AdDisplayDays,
                adaddressatpublicsecuritynearlandmarkname = dto.AddressPartiesMeetingLandmark,
            };

            var template = Scriban.Template.Parse(html);

            if (template.HasErrors)
            {
                throw new Exception(string.Join <Scriban.Parsing.LogMessage>(',', template.Messages.ToArray()));
            }
            string result = template.Render(anonymousDataObject);

            return(result);
        }
Пример #18
0
        public IActionResult CreateAd([FromBody] AdDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Errors()));
            }

            KeyValuePair <bool, string> kvp = model.IsValidCreateAdInputs(_configuration, _jsonDataService);

            if (kvp.Key)
            {
                return(BadRequest("In valid inputs: " + kvp.Value));
            }

            AdDto dto = _adCreateService.CreateAd(model);

            return(Ok(dto));
        }
Пример #19
0
 public IActionResult Post([FromBody] AdDto value)
 {
     if (value.CategoryId == 0)
     {
         return(StatusCode(406, "kategori secmedin"));
     }
     if (value.Title.Length < 3)
     {
         return(StatusCode(406, "baslik 3 karakterden az olamaz"));
     }
     value.IpAddress = IpAddress;
     if (UserRole != Roles.Administrator)
     {
         value.PosterId = UserId;
     }
     service.AddNewAd(value);
     return(Ok());
 }
Пример #20
0
        public IActionResult CreateAd([FromBody] AdDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Errors()));
            }
            model.Defaults(_configuration);
            if (_jsonDataService.IsValidCategory(model.AdCategoryId))
            {
                return(BadRequest(nameof(model.AdCategoryId)));
            }
            if (_jsonDataService.IsValidCallingCode(int.Parse(model.UserPhoneCountryCode)))
            {
                return(BadRequest(nameof(model.UserPhoneCountryCode)));
            }
            model.GoogleStorageAdFileDto = new GoogleStorageAdFileDto();
            model.GoogleStorageAdFileDto.Values(_configuration, model.AttachedAssetsInCloudStorageId.Value);
            AdDto dto = _adService.CreateAd(model);

            return(Ok(dto));
        }
Пример #21
0
        public async Task <IActionResult> UpdateAdvertisement(AdvertisementRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var ad = _adService.GetAd(request.Id);

            if (!ModelState.IsValid)
            {
                ad = new AdDto()
                {
                    Id          = request.Id,
                    Title       = request.Title,
                    Text        = request.Text,
                    CreatedDate = ad.CreatedDate,
                    ImagePath   = ad.ImagePath,
                    Number      = ad.Number,
                    Ratings     = ad.Ratings,
                    UserId      = ad.UserId,
                    UserName    = ad.UserName
                };

                return(View(ad));
            }

            try
            {
                await _adService.UpdateAdvertisement(request, User.Claims.GetUserId());
            }
            catch (UnauthorizedAccessException)
            {
                return(RedirectToAction("Index"));
            }

            return(RedirectToAction("Index"));
        }
Пример #22
0
 public AdData(AdDto ad, byte[] fileData, FileType type)
 {
     Ad       = ad;
     FileData = fileData;
     Type     = type;
 }
Пример #23
0
        public async Task AddAsync(AdDto adDto)
        {
            var ad = _mapper.Map <Ad>(adDto);

            await _adRepository.AddAsync(ad);
        }
Пример #24
0
 IEnumerator DownloadFile(AdDto ad, Action <byte[]> response)
 {
     if (Application.internetReachability == NetworkReachability.NotReachable)
     {
         response(default);