Exemplo n.º 1
0
        // Hirdetés módosítása
        public async Task <AdvertisementDetailedDTO> UpdateAdvertisement(string userName, int id, UpdateAdvertisementRequest request)
        {
            var advertisement = await AdvertisementRepository.FindByIdAsync(id);

            // Ha helytelen a felhasználónév
            if (advertisement.UserName != userName)
            {
                return(null);
            }

            advertisement      = request.FromDTO();
            advertisement.Id   = id;
            advertisement.User = await UserRepository.GetByName(userName);

            advertisement.UserName = userName;

            //Képek frissítése
            if (request.ImagesChanged)
            {
                await AdvertisementRepository.RemoveImages(advertisement);

                foreach (string image in request.ImageList)
                {
                    advertisement.Images.Add(new Image {
                        File = image
                    });
                }
            }

            //Validáció
            bool valid = await ValidateAsync(advertisement, request.ImagesChanged);

            //Előfizetés ellenőrzése
            bool success = SubscriptionService.CheckSubscription(advertisement.User, advertisement);

            if (valid && success)
            {
                advertisement.Status = advertisement.Priority.ToStatus();
                var result = await AdvertisementRepository.UpdateAsync(advertisement);

                return(result.ToDetailedDTO());
            }
            return(null);
        }
Exemplo n.º 2
0
        // Hirdetés létrehozása
        public async Task <AdvertisementDetailedDTO> CreateAdvertisement(string userName, CreateAdvertisementRequest request)
        {
            var advertisement = request.FromDTO();

            foreach (var detail in advertisement.Details)
            {
                detail.Id = 0;
            }

            //Felhasználó beállítása
            var user = await UserRepository.GetByNameWithDetails(userName);

            advertisement.User     = user;
            advertisement.UserName = user.UserName;

            //Dátum beállítása
            advertisement.UploadDate = DateTime.Today;

            //Képek beállítása
            foreach (string image in request.ImageList)
            {
                advertisement.Images.Add(new Image {
                    File = image
                });
            }

            //Előfizetés ellenőrzése
            bool success = SubscriptionService.CheckSubscription(user, advertisement);

            //Validáció
            bool valid = await ValidateAsync(advertisement);

            if (success && valid)
            {
                advertisement.Status = advertisement.Priority.ToStatus();
                await AdvertisementRepository.CreateAsync(advertisement);

                return(advertisement.ToDetailedDTO());
            }
            return(null);
        }