Example #1
0
        public async Task <IActionResult> Add(ConcertViewModel model)
        {
            if (ModelState.IsValid)
            {
                ConcertModel concert = await _context.Concerts.FirstOrDefaultAsync(u => u.Name == model.Name);

                if (concert == null)
                {
                    ConcertModel c = new ConcertModel(model);

                    if (model.Type == nameof(ClassicalConcertModel))
                    {
                        ClassicalConcertModel classicConcert = new ClassicalConcertModel(c);
                        classicConcert.VocalType            = model.VocalType;
                        classicConcert.ClassicalConcertName = model.ClassicalConcertName;
                        classicConcert.Composer             = model.Composer;

                        _context.ClassicalConcerts.Add(classicConcert);
                    }
                    else if (model.Type == nameof(OpenAirModel))
                    {
                        OpenAirModel openAir = new OpenAirModel(c);

                        openAir.DriveWay  = model.DriveWay;
                        openAir.Headliner = model.Headliner;

                        _context.OpenAirs.Add(openAir);
                    }
                    else if (model.Type == nameof(PartyModel))
                    {
                        PartyModel party = new PartyModel(c);
                        party.AgeQualification = model.AgeQualification.Value;
                        _context.Parties.Add(party);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Некорректные данные");
                    }

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Concerts"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные данные");
                }
            }
            else
            {
                ModelState.AddModelError("", "Некорректные данные");
            }
            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> Details(int?id, int?page = null)
        {
            ViewBag.Page = page;
            if (TempData["result"] != null)
            {
                ViewBag.Message     = TempData["result"].ToString();
                ViewBag.Message2    = TempData["success"];
                TempData["result"]  = null;
                TempData["success"] = false;
            }
            if (id == null)
            {
                return(NotFound());
            }

            var concert = await _context.Concerts
                          .SingleOrDefaultAsync(m => m.Id == id);

            if (concert == null)
            {
                return(NotFound());
            }
            ConcertViewModel model = new ConcertViewModel(concert);
            var type = concert.GetType().Name;

            if (type == nameof(ClassicalConcertModel))
            {
                ClassicalConcertModel classicalConcert = (ClassicalConcertModel)concert;
                model.ClassicalConcertName = classicalConcert.ClassicalConcertName;
                model.VocalType            = classicalConcert.VocalType;
                model.Composer             = classicalConcert.Composer;
            }
            else if (type == nameof(OpenAirModel))
            {
                OpenAirModel openAir = (OpenAirModel)concert;
                model.DriveWay  = openAir.DriveWay;
                model.Headliner = openAir.Headliner;
            }
            else
            {
                PartyModel party = (PartyModel)concert;
                model.AgeQualification = party.AgeQualification;
            }

            return(View(model));
        }
Example #3
0
        public async Task <IActionResult> Edit(int?id, int?page = null)
        {
            ViewBag.Page = page;
            if (id == null)
            {
                return(NotFound());
            }

            ConcertModel concert = await _context.Concerts.SingleOrDefaultAsync(m => m.Id == id);

            if (concert == null)
            {
                return(NotFound());
            }

            ConcertViewModel model = new ConcertViewModel(concert);

            if (concert.Type == nameof(ClassicalConcertModel))
            {
                ClassicalConcertModel currentClassic = await _context.ClassicalConcerts.SingleOrDefaultAsync(c => c.Id == id);

                model.ClassicalConcertName = currentClassic.ClassicalConcertName;
                model.Composer             = currentClassic.Composer;
                model.VocalType            = currentClassic.VocalType;
            }
            else if (concert.Type == nameof(OpenAirModel))
            {
                OpenAirModel currentOpenAir = await _context.OpenAirs.SingleOrDefaultAsync(c => c.Id == id);

                model.Headliner = currentOpenAir.Headliner;
                model.DriveWay  = currentOpenAir.DriveWay;
            }
            else if (concert.Type == nameof(PartyModel))
            {
                PartyModel currentParty = await _context.Parties.SingleOrDefaultAsync(c => c.Id == id);

                model.AgeQualification = currentParty.AgeQualification;
            }
            return(View(model));
        }
Example #4
0
        public async Task <IActionResult> Edit(int id, ConcertViewModel model, int?page = null)
        {
            ViewBag.Page = page;
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ConcertModel concert = await _context.Concerts.SingleOrDefaultAsync(c => c.Id == id);

                    if (concert.Type == model.Type)
                    {
                        if (model.Type == nameof(ClassicalConcertModel))
                        {
                            ClassicalConcertModel currentClassic = await _context.ClassicalConcerts.SingleOrDefaultAsync(c => c.Id == id);

                            currentClassic.Update(model);
                            _context.Update(currentClassic);
                        }
                        else if (model.Type == nameof(OpenAirModel))
                        {
                            OpenAirModel currentOpenAir = await _context.OpenAirs.SingleOrDefaultAsync(c => c.Id == id);

                            currentOpenAir.Update(model);
                            _context.Update(currentOpenAir);
                        }
                        else if (model.Type == nameof(PartyModel))
                        {
                            PartyModel currentParty = await _context.Parties.SingleOrDefaultAsync(c => c.Id == id);

                            currentParty.Update(model);
                            _context.Update(currentParty);
                        }
                    }
                    else
                    {
                        if (model.Type == nameof(ClassicalConcertModel))
                        {
                            ClassicalConcertModel newConcert = new ClassicalConcertModel(concert);
                            newConcert.Update(model);
                            _context.Concerts.Add(newConcert);
                        }
                        else if (model.Type == nameof(OpenAirModel))
                        {
                            OpenAirModel newConcert = new OpenAirModel(concert);
                            newConcert.Update(model);
                            _context.Concerts.Add(newConcert);
                        }
                        else if (model.Type == nameof(PartyModel))
                        {
                            PartyModel newConcert = new PartyModel(concert);
                            newConcert.Update(model);
                            _context.Concerts.Add(newConcert);
                        }
                        _context.Concerts.Remove(concert);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ConcertExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }