//Néhány hirdetés hozzáadása, ha az adatbázis üres
        private void SeedAdvertisements(IAdvertisementRepository advertisementRepository)
        {
            var user = UserManager.FindByNameAsync("admin").Result;

            for (int i = 0; i < 50; i++)
            {
                var request = new Advertisement {
                    Title = $"Hirdetes{i}", Description = "Valami leiras", Price = 100, Image = "house1.jpg", Status = Status.Displayed, UserName = "******", User = user, UploadDate = DateTime.Now, CategoryId = 1
                };
                request.Images.Add(new Image {
                    File = "house1.jpg"
                });
                var result = advertisementRepository.CreateAsync(request).Result;
            }

            for (int i = 0; i < 50; i++)
            {
                var request = new Advertisement {
                    Title = $"Fontos hirdetes{i}", Description = "Valami leiras", Price = 200, Image = "house3.jpg", Status = Status.Highlighted, UserName = "******", User = user, UploadDate = DateTime.Now, CategoryId = 1
                };
                request.Images.Add(new Image {
                    File = "house1.jpg"
                });
                var result = advertisementRepository.CreateAsync(request).Result;
            }

            for (int i = 0; i < 50; i++)
            {
                var request = new Advertisement {
                    Title = $"Kiemelt hirdetes{i}", Description = "Valami leiras a hirdetesrol", Price = 300, Image = "house2.jpg", Status = Status.Featured, Priority = Priority.Featured, UserName = "******", User = user, UploadDate = DateTime.Now, CategoryId = 1
                };
                request.Images.Add(new Image {
                    File = "house2.jpg"
                });
                var result = advertisementRepository.CreateAsync(request).Result;
            }
        }
示例#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);
        }
示例#3
0
 public async Task <Advertisement> CreateAsync(AdvertisementEntry advertisementEntry)
 {
     return(await _advertisementRepository.CreateAsync(advertisementEntry));
 }