public static GumtreeTopicDocument AsRelatedDocument(this GumtreeTopicDto dto, Guid parentGuid)
        {
            var document = DtoToDocument(dto);

            document.RelatedId    = parentGuid;
            document.PriceChanged = true;
            return(document);
        }
Esempio n. 2
0
        public async Task <ActionResult> Post(GumtreeTopicDto dto)
        {
            _validator.Validate(dto).ThrowIfInvalid();

            await _service.CreateAsync(dto);

            return(Created(dto.Id.ToString(), null));
        }
Esempio n. 3
0
        public async Task <ActionResult> Put(Guid id, GumtreeTopicDto dto)
        {
            dto.Id = id;
            _validator.Validate(dto).ThrowIfInvalid();

            await _service.UpdateAsync(dto);

            return(Ok());
        }
Esempio n. 4
0
 public IValitResult Validate(GumtreeTopicDto dto, IValitStrategy strategy = null)
 => ValitRules <GumtreeTopicDto>
 .Create()
 .WithStrategy(s => s.Complete)
 .Ensure(c => c.Title, _ => _
         .Required())
 .Ensure(c => c.Url, _ => _
         .Required())
 .For(dto)
 .Validate();
Esempio n. 5
0
        public async Task CreateAsync(GumtreeTopicDto dto)
        {
            var collection = _database.GetCollection <GumtreeTopicDocument>("GumTreeTopics")
                             .AsQueryable()
                             .OrderBy(x => x.TimeStamp)
                             .Where(x => x.Url == dto.Url)
                             .ToList();

            if (!collection.Any())
            {
                await _repository.AddAsync(dto.AsDocument());

                return;
            }

            var firstDocument = collection.ElementAt(0);
            var lastDocument  = collection.TakeLast(1).FirstOrDefault(c => c.Url == dto.Url && c.Price != dto.Price);

            if (lastDocument is { })
        private static GumtreeTopicDocument DtoToDocument(GumtreeTopicDto dto)
        {
            var document = new GumtreeTopicDocument
            {
                Id           = dto.Id,
                PropertyType = dto.PropertyType,
                Garage       = dto.Garage,
                Price        = dto.Price,
                TimeStamp    = DateTime.Now,
                Title        = dto.Title,
                Url          = dto.Url,
                SizeM2       = dto.SizeM2,
                City         = dto.City.Contains(dto.Province)
                    ? dto.City.Replace(dto.Province, "").Replace(" ", "").Replace(",", "")
                    : dto.City,
                Province    = dto.Province,
                PricePerM2  = Math.Round(dto.Price / dto.SizeM2, 3),
                Description = dto.Description,
                CreatedDate = Convert.ToDateTime(dto.CreatedDate)
            };

            return(document);
        }
 public static GumtreeTopicDocument AsDocument(this GumtreeTopicDto dto)
 {
     return(DtoToDocument(dto));
 }