Exemplo n.º 1
0
        public static HorseAdDTO FromHorseAdToHorseAdDTO(HorseAd horseAd)
        {
            var horseAdDTO = new HorseAdDTO
            {
                Id          = horseAd.Id.ToString(),
                UserId      = horseAd.UserId,
                HorseName   = horseAd.HorseName,
                Abilities   = horseAd.Abilities.Select(UtilConverter.FromHorseAbilityToHorseAbilityDTO),
                Address     = FromAddressToAddressDTO(horseAd.Address),
                Pedigree    = FromPedigreeToPedigreeDTO(horseAd.Pedigree),
                Price       = horseAd.Price != 0M ? horseAd.Price.ToString("##,#", _cultureInfo) : "",
                PriceRange  = UtilConverter.FromPriceRangeToPriceRangeDTO(horseAd.PriceRange),
                Breed       = horseAd.Breed,
                Age         = horseAd.Age,
                Description = horseAd.Description,
                Gender      = horseAd.Gender,
                HaveCompetionalExperience = horseAd.HaveCompetionalExperience,
                HaveXRays         = horseAd.HaveXRays,
                Images            = horseAd.Images.Select(UtilConverter.FromImageToImageDTO),
                RecomendedRiders  = horseAd.RecomendedRiders.Select(UtilConverter.FromRiderToRiderDTO),
                IsSponsorized     = horseAd.IsSponsorized,
                VideoLink         = horseAd.VideoLink,
                DatePosted        = horseAd.DatePosted,
                Title             = horseAd.Title,
                IsValidated       = horseAd.IsValidated,
                HeightInCm        = horseAd.Height,
                CountFavoritesFor = horseAd.FavoriteFor?.Count ?? 0,
                Views             = horseAd.Views,
                FavoritesFor      = horseAd.FavoriteFor?.Where(x => !x.IsDeleted).Select(x => x.UserId) ?? new List <string>(),
                IsSold            = horseAd.IsSold
            };

            return(horseAdDTO);
        }
Exemplo n.º 2
0
        public static HorseAd FromHorseAdDTOToHorseAd(HorseAdDTO horseAdDTO, string userId)
        {
            var horseAd = new HorseAd
            {
                HorseName        = horseAdDTO.HorseName,
                HorseAbilitesIds = horseAdDTO.AbilityIds,
                Address          = FromAddressDTOToAddress(horseAdDTO.Address),
                Pedigree         = FromPedigreeDTOToPedigree(horseAdDTO.Pedigree),
                Price            = Convert.ToDecimal(horseAdDTO.Price),
                PriceRangeId     = horseAdDTO.PriceRangeId,
                Breed            = horseAdDTO.Breed,
                Age         = horseAdDTO.Age,
                Description = horseAdDTO.Description,
                Gender      = horseAdDTO.Gender,
                HaveCompetionalExperience = horseAdDTO.HaveCompetionalExperience,
                HaveXRays           = horseAdDTO.HaveXRays,
                RecommendedRiderIds = horseAdDTO.RecomendedRidersIds,
                IsSponsorized       = horseAdDTO.IsSponsorized,
                VideoLink           = horseAdDTO.VideoLink,
                DatePosted          = DateTime.UtcNow,
                Title       = SetAdTitle(horseAdDTO),
                Height      = horseAdDTO.HeightInCm,
                Images      = horseAdDTO.Images.Select(UtilConverter.FromImageDTOToImage).ToList(),
                IsValidated = false,
                UserId      = userId
            };

            return(horseAd);
        }
Exemplo n.º 3
0
        public async Task Add(HorseAdDTO horseAdDTO, string userId)
        {
            ValidateHorseAd(horseAdDTO);

            var horseAd = HorseAdConverter.FromHorseAdDTOToHorseAd(horseAdDTO, userId);

            await _iHorseAdDao.AddHorse(horseAd);

            await SendEmailToAdmin();
        }
Exemplo n.º 4
0
        public async Task EditHorseAd(int id, HorseAdDTO horseAdDTO, string userId)
        {
            ValidateHorseAd(horseAdDTO);

            var horseAd = _iHorseAdDao.GetById(id);

            CheckHorseAdAndUserIdentity(horseAd, userId);

            var updatedHorseAd = UpdateHorseAd(horseAd, horseAdDTO);

            await _iHorseAdDao.EditHorseAdAsync(updatedHorseAd);
        }
Exemplo n.º 5
0
        private HorseAd UpdateHorseAd(HorseAd horseAd, HorseAdDTO horseAdDTO)
        {
            horseAd.HorseName        = horseAdDTO.HorseName;
            horseAd.HorseAbilitesIds = horseAdDTO.AbilityIds;
            horseAd.Price            = !string.IsNullOrEmpty(horseAdDTO.Price) ? Convert.ToDecimal(horseAdDTO.Price) : 0M;
            horseAd.PriceRangeId     = horseAdDTO.PriceRangeId;
            horseAd.Breed            = horseAdDTO.Breed;
            horseAd.Age         = horseAdDTO.Age;
            horseAd.Description = horseAdDTO.Description;
            horseAd.Gender      = horseAdDTO.Gender;
            horseAd.HaveCompetionalExperience = horseAdDTO.HaveCompetionalExperience;
            horseAd.HaveXRays           = horseAdDTO.HaveXRays;
            horseAd.RecommendedRiderIds = horseAdDTO.RecomendedRidersIds;
            horseAd.IsSponsorized       = horseAdDTO.IsSponsorized;
            horseAd.VideoLink           = horseAdDTO.VideoLink;
            horseAd.Title  = HorseAdConverter.SetAdTitle(horseAdDTO);
            horseAd.Height = horseAdDTO.HeightInCm;

            horseAd.Address.City    = horseAdDTO.Address.City;
            horseAd.Address.Country = horseAdDTO.Address.Country;
            horseAd.Address.Street  = horseAdDTO.Address.Street;

            if (horseAd.Pedigree != null)
            {
                horseAd.Pedigree.Father               = horseAdDTO.Pedigree.Father;
                horseAd.Pedigree.Father_Father        = horseAdDTO.Pedigree.Father_Father;
                horseAd.Pedigree.Father_Mother        = horseAdDTO.Pedigree.Father_Mother;
                horseAd.Pedigree.Father_Father_Father = horseAdDTO.Pedigree.Father_Father_Father;
                horseAd.Pedigree.Father_Father_Mother = horseAdDTO.Pedigree.Father_Father_Mother;
                horseAd.Pedigree.Father_Mother_Father = horseAdDTO.Pedigree.Father_Mother_Father;
                horseAd.Pedigree.Father_Mother_Mother = horseAdDTO.Pedigree.Father_Mother_Mother;
                horseAd.Pedigree.Mother               = horseAdDTO.Pedigree.Mother;
                horseAd.Pedigree.Mother_Father        = horseAdDTO.Pedigree.Mother_Father;
                horseAd.Pedigree.Mother_Mother        = horseAdDTO.Pedigree.Mother_Mother;
                horseAd.Pedigree.Mother_Father_Father = horseAdDTO.Pedigree.Mother_Father_Father;
                horseAd.Pedigree.Mother_Father_Mother = horseAdDTO.Pedigree.Mother_Father_Mother;
                horseAd.Pedigree.Mother_Mother_Father = horseAdDTO.Pedigree.Mother_Mother_Father;
                horseAd.Pedigree.Mother_Mother_Mother = horseAdDTO.Pedigree.Mother_Mother_Mother;
            }
            else
            {
                horseAd.Pedigree = HorseAdConverter.FromPedigreeDTOToPedigree(horseAdDTO.Pedigree);
            }

            return(horseAd);
        }
Exemplo n.º 6
0
        private void ValidateHorseAd(HorseAdDTO horseAdDTO)
        {
            if (horseAdDTO == null)
            {
                throw new ValidationException(Resources.InvalidHorseAdRequest);
            }

            ValidationHelper.ValidateModelAttributes <HorseAdDTO>(horseAdDTO);
            ValidationHelper.ValidateModelAttributes <AddressDTO>(horseAdDTO.Address);

            if (!horseAdDTO.AbilityIds.Any())
            {
                throw new ValidationException(Resources.MustSelectAtLeastOneAbility);
            }

            if (!horseAdDTO.RecomendedRidersIds.Any())
            {
                throw new ValidationException(Resources.MustSelectAtLeastOneRecommendedRider);
            }
        }
Exemplo n.º 7
0
        public static string SetAdTitle(HorseAdDTO horseAdDTO)
        {
            var title = horseAdDTO.Age + "y " + horseAdDTO.HorseName;

            return(title);
        }
Exemplo n.º 8
0
 public async Task Update([FromUri] int id, [FromBody] HorseAdDTO horseAdDTO)
 {
     await _iHorseAdBus.EditHorseAd(id, horseAdDTO, UserIdExtractor.GetUserIdFromRequest(Request));
 }
Exemplo n.º 9
0
 public async Task Post([FromBody] HorseAdDTO horseAdDTO)
 {
     await _iHorseAdBus.Add(horseAdDTO, UserIdExtractor.GetUserIdFromRequest(Request));
 }