Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Length")] Advert advert)
        {
            if (ModelState.IsValid)
            {
                _context.Add(advert);
                await _context.SaveChangesAsync();

                _service.BookAdvert(advert);
                return(RedirectToAction(nameof(Index)));
            }
            return(View(advert));
        }
        public async Task <IActionResult> AddAvitoRentAdverts([FromBody] RentURLFilterModel model)
        {
            var adverts = await HTMLParser.ParseAdvertsFromURL(model.ToURLString());

            foreach (AdvertModel advert in adverts)
            {
                var existingadvert = _context.Adverts.SingleOrDefault(row => row.Url == advert.Url);
                if (existingadvert != null)
                {
                    continue;
                }

                _context.Adverts.Add(advert);
                await _context.SaveChangesAsync();
            }

            return(Ok(model.ToURLString()));
        }
Ejemplo n.º 3
0
        public async Task <bool> Register(string username, string password)
        {
            using (var db = new AdvertContext())
            {
                var user = await db.Users.SingleOrDefaultAsync(x => x.Username == username && x.Password == password);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Email = username, Password = password
                    });
                    await db.SaveChangesAsync();

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public async Task <Campaign> CreateAsync(CampaignCreateRequest model,
                                                 CampaignCreateResponse calculation)
        {
            var campaign = _mapper.Map <Campaign>(model);

            await _context.Campaigns.AddAsync(campaign);

            if (await _context.SaveChangesAsync() == 0)
            {
                // TODO: Log errors
                return(null);
            }
            var bannerModel1 = new Banner
            {
                IdCampaign = campaign.IdCampaign,
                Area       = calculation.Banner1.SquareMeters,
                Name       = 0,
                Price      = calculation.Banner1.Price
            };
            var bannerModel2 = new Banner
            {
                IdCampaign = campaign.IdCampaign,
                Area       = calculation.Banner2.SquareMeters,
                Name       = 0,
                Price      = calculation.Banner2.Price
            };

            var banner1 = await _bannerCreateService.Create(bannerModel1);

            var banner2 = await _bannerCreateService.Create(bannerModel2);

            if (banner1 == null || banner2 == null)
            {
                return(null);
            }


            return(campaign);
        }
Ejemplo n.º 5
0
 public async Task <int> SaveAsync()
 {
     return(await _context.SaveChangesAsync());
 }