public void Add_SimpleItem_OK()
        {
            FootballClub newEntity = new FootballClub
            {
                CityId        = 1,
                Name          = "New Team",
                Members       = 0,
                Stadium       = "New Stadium",
                FundationDate = DateTime.Today
            };

            int result   = instance.Add(newEntity);
            int expected = 1;

            Assert.AreEqual(expected, result);
        }
Exemple #2
0
        // GET: FootballClubs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            FootballClub footballClub = _repository.Find(id);

            if (footballClub == null)
            {
                return(HttpNotFound());
            }

            return(View(footballClub));
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            FootballClub = await _context.FootballClub.FindAsync(id);

            if (FootballClub != null)
            {
                _context.FootballClub.Remove(FootballClub);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public HttpResponseMessage Edit(int id)
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage();

            StreamReader nameReader = null;
            string       name       = null;
            string       logoPath   = null;
            FileStream   logoStream = null;
            Stream       str        = null;

            try
            {
                nameReader = new StreamReader(Request.Form.Files[0].OpenReadStream());
                name       = nameReader.ReadToEnd();

                logoPath = imagesDirectory + name + "_logo.png";

                logoStream = new FileStream(logoPath, FileMode.Create, FileAccess.Write);
                str        = Request.Form.Files[1].OpenReadStream();
                str.CopyTo(logoStream);
            }
            catch (Exception e)
            {
                httpResponse.StatusCode   = System.Net.HttpStatusCode.BadRequest;
                httpResponse.ReasonPhrase = e.Message;
            }
            finally
            {
                nameReader.Close();
                str.Close();
                logoStream.Close();
            }


            FootballClub clubToEdit = FootballClub.clubs.First(c => c.Id == id);

            clubToEdit.Name      = name;
            clubToEdit.ImagePath = logoPath;

            EditInXml(clubToEdit);

            httpResponse.StatusCode = System.Net.HttpStatusCode.OK;

            return(httpResponse);
        }
        public void Update_OK()
        {
            /// changed values for tests

            FootballClub updateEntity = new FootballClub
            {
                Id            = 45,
                CityId        = 1,
                Name          = "New Team 3",
                Members       = 10,
                Stadium       = "New Stadium 3",
                FundationDate = DateTime.Today
            };

            int result   = instance.Update(updateEntity);
            int expected = 0;

            Assert.AreEqual(expected, result);
        }
        public async Task UpdateAsync_OK()
        {
            /// changed values for tests

            FootballClub updateEntity = new FootballClub
            {
                Id            = 44,
                CityId        = 1,
                Name          = "New Team 2",
                Members       = 10,
                Stadium       = "New Stadium 2",
                FundationDate = DateTime.Today
            };

            int result = await instance.UpdateAsync(updateEntity);

            int expected = 0;

            Assert.AreEqual(expected, result);
        }
        public async Task RemoveAsync_SimpleItem_forEntity_OK()
        {
            /// changed pk for tests

            FootballClub removeEntity = new FootballClub
            {
                Id            = 9999,
                CityId        = 1,
                Name          = "New Team",
                Members       = 0,
                Stadium       = "New Stadium",
                FundationDate = DateTime.Today
            };

            int result = await instance.RemoveAsync(removeEntity);

            int expected = 0;

            Assert.AreEqual(expected, result);
        }
Exemple #8
0
        private void addPlayerButton_Click(object sender, EventArgs e)
        {
            string error = string.Empty;

            if (playerNameTextBox.Text.Length == 0 || playerNameTextBox.Text[0] == ' ')
            {
                error += "Nezadali jste platné jméno hráče!" + Environment.NewLine;
            }

            if (playerCountGolTextBox.Text.Length == 0 || !int.TryParse(playerCountGolTextBox.Text, out _))
            {
                error += "Nezadali jste platný počet gólů!";
            }

            if (!error.Equals(string.Empty))
            {
                return;
            }

            string       playerName   = playerNameTextBox.Text;
            FootballClub footballClub = ((FootballClub)playerClubComboBox.SelectedIndex);

            int.TryParse(playerCountGolTextBox.Text, out var countGols);

            if (player == null)
            {
                Player tempPlayer = new Player(playerName, footballClub, countGols);
                playerHandler(tempPlayer);
            }
            else
            {
                player.Name      = playerName;
                player.Club      = footballClub;
                player.GolsCount = countGols;
                playerHandler(player);
            }

            Close();
        }
            public static FootballClub[] ParseFromText(string text)
            {
                ReguexAttribute attr = typeof(FootballClub).GetTypeInfo().GetCustomAttribute <ReguexAttribute>();

                string regexPerson  = attr.Pattern;
                var    clubsMatches = Regex.Matches(text, regexPerson);

                FootballClub[] clubs = new FootballClub[clubsMatches.Count];

                for (int i = 0; i < clubsMatches.Count; i++)
                {
                    var match = clubsMatches[i];

                    try
                    {
                        string name = match.Groups[1].Value;

                        string originCity     = match.Groups[2].Value;
                        uint   foundationYear = UInt32.Parse(match.Groups[3].Value);

                        clubs[i] = new FootballClub(name, originCity, foundationYear);
                    }
                    catch (IndexOutOfRangeException)
                    {
                        Console.Write("Check indexes of matches");
                    }
                    catch (ArgumentNullException)
                    {
                        Console.Write("No text to parse for year");
                    }
                    catch (FormatException)
                    {
                        Console.Write("Year could not be parsed");
                    }
                }

                return(clubs);
            }
        public HttpResponseMessage Add(int id, string name)
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage();

            string logoPath = imagesDirectory + name + "_logo.png";

            FileStream logoStream = null;

            try
            {
                logoStream = new FileStream(logoPath, FileMode.Create, FileAccess.Write);
                Stream str = Request.Form.Files[0].OpenReadStream();
                str.CopyTo(logoStream);
                str.Close();
            }
            catch (Exception e)
            {
                httpResponse.StatusCode   = System.Net.HttpStatusCode.BadRequest;
                httpResponse.ReasonPhrase = e.Message;
                return(httpResponse);
            }
            finally
            {
                logoStream.Close();
            }

            FootballClub newClub = new FootballClub(id, name, logoPath);

            FootballClub.clubs.Add(newClub);
            AppendToXml(newClub);

            httpResponse.StatusCode   = System.Net.HttpStatusCode.OK;
            httpResponse.ReasonPhrase = "Данные сохранены";

            return(httpResponse);
        }
        public HttpResponseMessage Remove(int id)
        {
            HttpResponseMessage httpResponse = new HttpResponseMessage(System.Net.HttpStatusCode.OK);

            FootballClub clubToRemove = FootballClub.clubs.First(c => c.Id == id);

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("clubs.xml");
            XmlElement xRoot = xDoc.DocumentElement;

            foreach (XmlNode node in xRoot)
            {
                if (node.Attributes.Count > 0)
                {
                    XmlNode attr = node.Attributes.GetNamedItem("id");
                    if (attr.Value == id.ToString())
                    {
                        xRoot.RemoveChild(node);
                        break;
                    }
                }
            }
            xDoc.Save("clubs.xml");

            string logoPath = imagesDirectory + clubToRemove.Name + "_logo.png";

            if (System.IO.File.Exists(logoPath))
            {
                System.IO.File.Delete(logoPath);
            }

            FootballClub.clubs.Remove(clubToRemove);

            return(httpResponse);
        }
        internal void EditInXml(FootballClub club)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("clubs.xml");
            XmlElement xRoot = xDoc.DocumentElement;

            foreach (XmlNode node in xRoot)
            {
                if (node.Attributes.Count > 0)
                {
                    if (node.Attributes.GetNamedItem("id").Value == club.Id.ToString())
                    {
                        node.RemoveAll();

                        XmlAttribute idAttr        = xDoc.CreateAttribute("id");
                        XmlElement   nameElem      = xDoc.CreateElement("name");
                        XmlElement   imagePathElem = xDoc.CreateElement("imagePath");

                        XmlText idText        = xDoc.CreateTextNode(club.Id.ToString());
                        XmlText nameText      = xDoc.CreateTextNode(club.Name);
                        XmlText imagePathText = xDoc.CreateTextNode(club.ImagePath);

                        idAttr.AppendChild(idText);
                        nameElem.AppendChild(nameText);
                        imagePathElem.AppendChild(imagePathText);
                        node.Attributes.Append(idAttr);
                        node.AppendChild(nameElem);
                        node.AppendChild(imagePathElem);

                        break;
                    }
                }
            }
            xDoc.Save("clubs.xml");
        }
 public void SendMessage(string from, FootballClub recipient, string message)
 {
     recipient.ReceiveMessage(from, message);
 }
Exemple #14
0
 public void SetCurrentClub(FootballClub club)
 {
     this.CurrentClub = club;
 }
 public FotbalovyKlubInfo(FootballClub fotbalovyKlub)
 {
     this.fotbalovyKlub = fotbalovyKlub;
 }
Exemple #16
0
 public void UpdateCurrentClub(FootballClub newClub)
 {
     this.PreviousClub = this.CurrentClub;
     this.CurrentClub  = newClub;
     this.UpdateJustMoved();
 }
 private void NavigateToClubPage(Program program, FootballClub club)
 {
     program.AddPage(new TeamView(program, club));
     program.NavigateTo <TeamView>();
 }
 public InsertViewModel(FootballClub model, IDisconGenericRepository <FootballClub> repository)
 {
     Model       = model;
     _repository = repository;
 }
        public void Find_PksNull_ThrowException()
        {
            object[] pks = null;

            FootballClub result = instance.Find(pks);
        }
Exemple #20
0
 public async Task <string> AddFootballClubs(FootballClub footballClub)
 {
     return(await _service.AddFootballClubs(footballClub));
 }
Exemple #21
0
 public Player(string name, FootballClub club, int numberOfGoals)
 {
     Name          = name;
     Club          = club;
     NumberOfGoals = numberOfGoals;
 }
Exemple #22
0
 public TeamView(Program program, FootballClub club)
     : base($"{club.Name}", program)
 {
     this.Club = club;
 }
 public LeagueFixture(FootballClub homeTeam, FootballClub awayTeam)
 {
     this.HomeTeam = homeTeam;
     this.AwayTeam = awayTeam;
 }
Exemple #24
0
 public Player(string name, FootballClub club, int goalCount)
 {
     Name      = name;
     Club      = club;
     GoalCount = goalCount;
 }
 public void SendOffer(FootballClub buyerClub, FootballClub sellerClub, Player playerToBeTraded)
 {
     sellerClub.ProcessOffer(buyerClub, playerToBeTraded);
 }