public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Info,Fb2,Pdf,PagesQuantity,Picture")] Book book, int[] genres, int[] authors)
        {
            var AreRepeats = _context.Books.Where(obj => obj.Name == book.Name && obj.PagesQuantity == book.PagesQuantity);

            foreach (var a in AreRepeats)
            {
                bool flag   = false;
                var  aBooks = _context.AuthorsBooks.Where(obj => obj.BookId == a.Id);
                foreach (var author in authors)
                {
                    if (aBooks.Where(obj => obj.AuthorId == author).Count() > 0)
                    {
                        flag = true;
                    }
                    break;
                }
                if (flag)
                {
                    ModelState.AddModelError("", "Така книга вже існує");
                    break;
                }
            }

            if (ModelState.IsValid)
            {
                _context.Add(book);

                foreach (int GId in genres)
                {
                    GenresBook gb = new GenresBook {
                        GenreId = GId, BookId = book.Id
                    };
                    book.GenresBooks.Add(gb);
                }


                foreach (int AId in authors)
                {
                    AuthorsBook ab = new AuthorsBook {
                        AuthorId = AId, BookId = book.Id
                    };
                    book.AuthorsBooks.Add(ab);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.Genres  = _context.Genres.ToList();
            ViewBag.Authors = _context.Authors.ToList();
            return(View(book));
        }
示例#3
0
        public async Task <IActionResult> Create(int teamId, [Bind("PlayerId,FirstName,LastName,ClubId,DateOfBirth,CountryId,Biography")] Player player)
        {
            player.TeamId = teamId;

            if ((DateTime.Now.Year - player.DateOfBirth.Value.Year) < 18 || (DateTime.Now.Year - player.DateOfBirth.Value.Year) > 120)
            {
                ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "CountryName");
                ModelState.AddModelError("DateOfBirth", "Неправильна дата");
                return(View(player));
            }

            if (ModelState.IsValid)
            {
                _context.Add(player);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "PlayersForTeams", new { id = teamId, name = _context.Teams.Include(t => t.Country).Where(c => c.TeamId == teamId).FirstOrDefault().Country.CountryName }));
            }
            string messages = string.Join("; ", ModelState.Values
                                          .SelectMany(x => x.Errors)
                                          .Select(x => x.ErrorMessage));

            //  ViewData["ClubId"] = new SelectList(_context.Clubs, "ClubId", "ClubId", player.Club.ClubName);
            //  ViewData["CountryId"] = new SelectList(_context.Countries, "CountryId", "CountryId", player.Country.CountryName);
            //  ViewData["TeamId"] = new SelectList(_context.Teams, "TeamId", "TeamId", player.TeamId);
            //  return View(player);
            return(RedirectToAction("Index", "PlayersForTeams", new { id = player.TeamId }));
        }
示例#4
0
        public async Task <IActionResult> Create([Bind("CountryId,CoachFirstName,CoachLastName,CoachDateOfBirth,CoachBiography")] Team team)
        {
            if ((DateTime.Now.Year - team.CoachDateOfBirth.Year) < 18 || (DateTime.Now.Year - team.CoachDateOfBirth.Year) > 120)
            {
                var existedTeams1 = _context.Teams.Include(t => t.Country).Select(t => t.Country);
                ViewData["CountryId"] = new SelectList(_context.Countries.ToList().Except(existedTeams1), "CountryId", "CountryName");
                ModelState.AddModelError("CoachDateOfBirth", "Неправильна дата");
                return(View(team));
            }

            if (ModelState.IsValid)
            {
                _context.Add(team);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            string messages = string.Join("; ", ModelState.Values
                                          .SelectMany(x => x.Errors)
                                          .Select(x => x.ErrorMessage));

            var existedTeams = _context.Teams.Include(t => t.Country).Select(t => t.Country);

            ViewData["CountryId"] = new SelectList(_context.Countries.ToList().Except(existedTeams), "CountryId", "CountryName");
            return(View(team));
        }
示例#5
0
        public async Task <IActionResult> Create([Bind("GenreId,GenreName,Description")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genre);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(genre));
        }
示例#6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Info")] Reader reader)
        {
            if (ModelState.IsValid)
            {
                _context.Add(reader);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(reader));
        }
示例#7
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Country country)
        {
            if (ModelState.IsValid)
            {
                _context.Add(country);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Create", "Authors"));
            }
            return(View(country));
        }
        public async Task <IActionResult> Create([Bind("AnimeInfoId,StudioName,Status,AgeRating,Type,Description,Source,Season")] AnimeInfo animeInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(animeInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(animeInfo));
        }
示例#9
0
        public async Task <IActionResult> Create([Bind("Id,Name,YearBirth,Information,CountryId")] GenManagers genManagers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(genManagers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Id", genManagers.CountryId);
            return(View(genManagers));
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Info,DateTime,BookId")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BookId"] = new SelectList(_context.Books, "Id", "Fb2", comment.BookId);
            return(View(comment));
        }
        public async Task <IActionResult> Create([Bind("AnimeId,Poster,AnimeName,Rating,AnimeInfoId")] Anime anime)
        {
            if (ModelState.IsValid)
            {
                _context.Add(anime);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AnimeInfoId"] = new SelectList(_context.AnimeInfos, "AnimeInfoId", "Description", anime.AnimeInfoId);
            return(View(anime));
        }
示例#12
0
        public async Task <IActionResult> Create(int categoryId, [Bind("Id,Name,Info")] Manga manga)
        {
            manga.CategoryId = categoryId;
            if (ModelState.IsValid)
            {
                _context.Add(manga);
                await _context.SaveChangesAsync();

                // return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "Mangas", new { id = categoryId, name = _context.Categories.Where(c => c.Id == categoryId).FirstOrDefault().Name }));
            }
            //ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", manga.CategoryId);
            //return View(manga);
            return(RedirectToAction("Index", "Mangas", new { id = categoryId, name = _context.Categories.Where(c => c.Id == categoryId).FirstOrDefault().Name }));
        }
        public async Task <IActionResult> Create(int authorId, [Bind("Id,MangaId,AuthorId")] AuthorsManga authorsManga)
        {
            if (ModelState.IsValid)
            {
                _context.Add(authorsManga);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "AuthorsMangas", new { id = authorId, name = _context.Authors.Where(c => c.Id == authorId).FirstOrDefault().Name }));
            }
            //ViewData["AuthorId"] = new SelectList(_context.Authors, "Id", "Name", authorsManga.AuthorId);
            ViewData["MangaId"] = new SelectList(_context.Mangas, "Id", "Name", authorsManga.MangaId);
            //return View(authorsManga);
            return(RedirectToAction("Index", "AuthorsMangas", new { id = authorId, name = _context.Authors.Where(c => c.Id == authorId).FirstOrDefault().Name }));
        }
        public async Task <IActionResult> CreateForCompany(int companyId, [Bind("Id,CompanyId,ProductId")] CompanyProducts companyProducts)
        {
            companyProducts.CompanyId = companyId;
            if (ModelState.IsValid)
            {
                var comp_prod = _context.CompanyProducts.Where(c => c.ProductId == companyProducts.ProductId).Where(c => c.CompanyId == companyId).FirstOrDefault();
                if (comp_prod != null)
                {
                    ModelState.AddModelError("Error", "Для цієї компанії вже існує дана категорія");
                }
                else
                {
                    _context.Add(companyProducts);
                    await _context.SaveChangesAsync();

                    //return RedirectToAction(nameof(Index));
                    return(RedirectToAction("IndexForCompany", "CompanyProducts", new { id = companyId, name = _context.Companies.Where(c => c.Id == companyId).FirstOrDefault().Name }));
                }
            }
            //ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", companyProducts.CompanyId);
            ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", companyProducts.ProductId);
            //return View(companyProducts);
            return(RedirectToAction("IndexForCompany", "CompanyProducts", new { id = companyId, name = _context.Companies.Where(c => c.Id == companyId).FirstOrDefault().Name }));
        }
        public async Task <IActionResult> Create(int readerId, [Bind("Id,ReaderId,MangaId,StatusId,PlanReturn,FactReturn")] ReadersManga readersManga)
        {
            if (ModelState.IsValid)
            {
                _context.Add(readersManga);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "ReadersMangas", new { id = readerId, name = _context.Readers.Where(c => c.Id == readerId).FirstOrDefault().Name }));
            }
            ViewData["MangaId"] = new SelectList(_context.Mangas, "Id", "Name", readersManga.MangaId);
            //ViewData["ReaderId"] = new SelectList(_context.Readers, "Id", "Name", readersManga.ReaderId);
            ViewData["StatusId"] = new SelectList(_context.Statuses, "Id", "Name", readersManga.StatusId);
            //return View(readersManga);
            return(RedirectToAction("Index", "ReadersMangas", new { id = readerId, name = _context.Readers.Where(c => c.Id == readerId).FirstOrDefault().Name }));
        }
        public async Task <IActionResult> Create([Bind("MatchId,MatchName,MatchResult,FirstClubId,SecondClubId,MatchDate")] ClubMatch clubMatch)
        {
            if (clubMatch.FirstClubId != clubMatch.SecondClubId)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(clubMatch);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["FirstClubId"]  = new SelectList(_context.Clubs, "ClubId", "ClubName");
            ViewData["SecondClubId"] = new SelectList(_context.Clubs, "ClubId", "ClubName");
            return(View(clubMatch));
        }
        public async Task <IActionResult> Create(int companyId, [Bind("Id,Name,Amount,CompanyId,CountryId")] Filials filial)
        {
            filial.CompanyId = companyId;
            if (ModelState.IsValid)
            {
                _context.Add(filial);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "Filials", new { id = companyId, name = _context.Companies.Where(c => c.Id == companyId).FirstOrDefault().Name }));
            }
            //ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Id", filials.CompanyId);
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "Id", filial.CountryId);
            //return View(filials);
            return(RedirectToAction("Index", "Filials", new { id = companyId, name = _context.Companies.Where(c => c.Id == companyId).FirstOrDefault().Name }));
        }
        public async Task <IActionResult> Create(int compProdId, [Bind("Id,Name,Price,Information,CompProdId,ColorId")] ModelsOfProduct modelsOfProduct)
        {
            modelsOfProduct.CompProdId = compProdId;
            var CompProd = _context.CompanyProducts.Where(c => c.Id == compProdId).FirstOrDefault();

            if (ModelState.IsValid)
            {
                _context.Add(modelsOfProduct);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "ModelsOfProducts", new { id = modelsOfProduct.CompProdId, companyId = CompProd.CompanyId, productId = CompProd.ProductId }));
            }
            //ViewData["ColorId"] = new SelectList(_context.Colors, "Id", "Id", modelsOfProduct.ColorId);
            //ViewData["CompProdId"] = new SelectList(_context.CompanyProducts, "Id", "Id", modelsOfProduct.CompProdId);
            //return View(modelsOfProduct);
            return(RedirectToAction("Index", "ModelsOfProducts", new { id = modelsOfProduct.CompProdId, companyId = CompProd.CompanyId, productId = CompProd.ProductId }));
        }
示例#19
0
        public async Task <IActionResult> Create([Bind("MatchId,MatchName,MatchResult,FirstTeamId,SecondTeamId,MatchDate")] TeamMatch teamMatch)
        {
            if (teamMatch.FirstTeamId != teamMatch.SecondTeamId)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(teamMatch);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            var teams = _context.Teams.Include(t => t.Country).Select(x => new { TeamId = x.TeamId, CountryName = x.Country.CountryName });

            ViewData["FirstTeamId"]  = new SelectList(teams, "TeamId", "CountryName");
            ViewData["SecondTeamId"] = new SelectList(teams, "TeamId", "CountryName");
            return(View(teamMatch));
        }
示例#20
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Countries countries)
        {
            if (ModelState.IsValid)
            {
                var country = _context.Countries.Where(c => c.Name == countries.Name).FirstOrDefault();
                if (country != null)
                {
                    ModelState.AddModelError(string.Empty, "Країна з такою назвою вже існує");
                }
                else
                {
                    _context.Add(countries);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(countries));
        }
示例#21
0
        public async Task <IActionResult> Create([Bind("Id,Name,Information")] Products products)
        {
            if (ModelState.IsValid)
            {
                var product = _context.Products.Where(c => c.Name == products.Name).FirstOrDefault();
                if (product != null)
                {
                    ModelState.AddModelError(string.Empty, "Категорія з такою назвою вже існує");
                }
                else
                {
                    _context.Add(products);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(products));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Info,BirthYear,DeathYear")] Author author, List <int> countries)
        {
            var IsRepeat = _context.Authors.Where(obj => obj.FirstName == author.FirstName && obj.LastName == author.LastName && obj.BirthYear == author.BirthYear);

            foreach (var item in IsRepeat)
            {
                bool flag = false;
                var  IsRepeatCountries = thisAuthorCountries(item.Id);
                foreach (var c in countries)
                {
                    if (IsRepeatCountries.Where(obj => obj.CountryId == c).Count() > 0)
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    ModelState.AddModelError("", "Такий автор вже існує");
                }
            }



            if (ModelState.IsValid)
            {
                _context.Add(author);

                foreach (var cID in countries)
                {
                    AuthorsCountry ac = new AuthorsCountry {
                        AuthorId = author.Id, CountryId = cID
                    };
                    author.AuthorsCountries.Add(ac);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.CountriesList = _context.Countries.ToList();
            return(View());
        }
示例#23
0
        public async Task <IActionResult> Create([Bind("Id,Name,Year,CountryId,GenManagerId")] Companies companies)
        {
            if (ModelState.IsValid)
            {
                var company = _context.Companies.Where(c => c.GenManagerId == companies.GenManagerId && c.GenManagerId != null).FirstOrDefault();
                if (company != null)
                {
                    ModelState.AddModelError(string.Empty, "У компанії може бути лише один ген.диретор. Обраний ген.директор має компанію");
                }
                else
                {
                    _context.Add(companies);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            ViewData["CountryId"]    = new SelectList(_context.Countries, "Id", "Name", companies.CountryId);
            ViewData["GenManagerId"] = new SelectList(_context.GenManagers, "Id", "Name", companies.GenManagerId);
            return(View(companies));
        }
示例#24
0
        public async Task <IActionResult> Create([Bind("ClubId,ClubName,CoachFirstName,CoachLastName,CoachDateOfBirth,StadiumName,StadiumCapacity,CoachBiography")] Club club)
        {
            if ((DateTime.Now.Year - club.CoachDateOfBirth.Value.Year) < 18 || (DateTime.Now.Year - club.CoachDateOfBirth.Value.Year) > 120)
            {
                ModelState.AddModelError("CoachDateOfBirth", "Неправильна дата");
                return(View(club));
            }

            if (club.StadiumCapacity < 0)
            {
                ModelState.AddModelError("StadiumCapacity", "Місткість не може бути від'ємною");
                return(View(club));
            }

            if (ModelState.IsValid)
            {
                _context.Add(club);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(club));
        }
        public async Task <IActionResult> Create([Bind("TransferId,SellerId,BuyerId,PlayerId,CostOfPlayer,Date")] Transfer transfer)
        {
            if (transfer.CostOfPlayer < 0)
            {
                ModelState.AddModelError("CostOfPlayer", "Ціна не може бути від'ємною");
                ViewData["BuyerId"]  = new SelectList(_context.Clubs, "ClubId", "ClubName");
                ViewData["PlayerId"] = new SelectList(_context.Players.Where(x => x.ClubId > 0), "PlayerId", "LastName");
                ViewData["SellerId"] = new SelectList(_context.Clubs, "ClubId", "ClubName");
                return(View(transfer));
            }

            if (_context.Players.Where(x => x.ClubId == transfer.SellerId).Any(x => x.PlayerId == transfer.PlayerId))
            {
                if (transfer.SellerId != transfer.BuyerId)
                {
                    if (ModelState.IsValid)
                    {
                        _context.Add(transfer);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    ModelState.AddModelError("BuyerId", "Команди співпадають");
                }
            }
            else
            {
                ModelState.AddModelError("PlayerId", "Гравець не з команди продавця");
            }
            ViewData["BuyerId"]  = new SelectList(_context.Clubs, "ClubId", "ClubName");
            ViewData["PlayerId"] = new SelectList(_context.Players.Where(x => x.ClubId > 0), "PlayerId", "LastName");
            ViewData["SellerId"] = new SelectList(_context.Clubs, "ClubId", "ClubName");
            return(View(transfer));
        }