예제 #1
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            News news = await _context.News.FindAsync(id);

            _context.News.Remove(news);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> Advertisement(Advertisement advertisement)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Model           = _context.Model;
                ViewBag.Brand           = _context.Brands;
                ViewBag.Colors          = _context.Colors;
                ViewBag.Fuels           = _context.Fuels;
                ViewBag.MachinePowers   = _context.MachinePowers;
                ViewBag.GraduationYears = _context.GradiuationYears;
                ViewBag.Speeds          = _context.Speeds;
                ViewBag.Cities          = _context.Cities;
                ModelState.AddModelError("", "Please input valid properties");

                return(View(advertisement));
            }

            Advertisement ad = new Advertisement()
            {
                ModelId           = advertisement.ModelId,
                Price             = advertisement.Price,
                ColorId           = advertisement.ColorId,
                MachinePowerId    = advertisement.MachinePowerId,
                FuelId            = advertisement.FuelId,
                Hiking            = advertisement.Hiking,
                GradiuationYearId = advertisement.GradiuationYearId,
                SpeedId           = advertisement.SpeedId,
                CarInfo           = advertisement.CarInfo,
                CityId            = advertisement.CityId,
                AdYear            = DateTime.Now,
            };

            _context.Advertisements.Add(ad);

            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }