コード例 #1
0
        public HttpResponseMessage GetImage(int playerId)
        {
            IPlayerDao playerDAO = DalFactory.CreatePlayerDao(database);
            Player     player    = playerDAO.FindById(playerId);


            string absolutePath = ConfigurationManager.AppSettings["ImageFolder"].ToString() + "\\";

            HttpResponseMessage response = new HttpResponseMessage();

            Byte[] b;

            if (player == null || !File.Exists(absolutePath + player.PhotoPath))
            {
                b = (File.ReadAllBytes(absolutePath + "default.png"));
            }
            else
            {
                absolutePath = absolutePath + player.PhotoPath;
                b            = (File.ReadAllBytes(absolutePath));
            }

            response.Content = new ByteArrayContent(b);
            response.Content.LoadIntoBufferAsync(b.Length).Wait();
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
            return(response);
        }
コード例 #2
0
        public HttpResponseMessage PostImage([FromBody] byte[] file, int playerId)
        {
            IPlayerDao playerDAO = DalFactory.CreatePlayerDao(database);
            Player     player    = playerDAO.FindById(playerId);

            try
            {
                using (MemoryStream ms = new MemoryStream(file))
                {
                    Image.FromStream(ms);
                }
            }
            catch (ArgumentException)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            string absolutePath = ConfigurationManager.AppSettings["ImageFolder"].ToString() + "\\" + player.PhotoPath;

            try
            {
                File.WriteAllBytes(absolutePath, file);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadGateway));
            }
        }
コード例 #3
0
        public HttpResponseMessage FindById(int id)
        {
            //if (Authentication.getInstance().isAuthenticateWithHeader(Request))
            //{
            IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database);

            return(Request.CreateResponse <Player>(HttpStatusCode.OK,
                                                   PlayerDao.FindById(id)));
            //}
            //else
            //{
            //	return new HttpResponseMessage(HttpStatusCode.Forbidden);
            //}
        }
コード例 #4
0
        public void Update(Match match)
        {
            //if (Authentication.getInstance().isAuthenticateWithHeader(Request))
            //{
            IMatchDao  MatchDao  = DalFactory.CreateMatchDao(database);
            IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database);


            if (match.Finished)
            {
                Player w1;
                Player w2;
                Player v1;
                Player v2;

                if (match.ResultPointsPlayer1 > match.ResultPointsPlayer2)
                {
                    w1 = PlayerDao.FindById(match.Team1Player1);
                    w2 = PlayerDao.FindById(match.Team1Player2);
                    v1 = PlayerDao.FindById(match.Team2Player1);
                    v2 = PlayerDao.FindById(match.Team2Player2);
                }
                else
                {
                    w1 = PlayerDao.FindById(match.Team2Player1);
                    w2 = PlayerDao.FindById(match.Team2Player2);
                    v1 = PlayerDao.FindById(match.Team1Player1);
                    v2 = PlayerDao.FindById(match.Team1Player2);
                }
                BLPlayer.UpdateElo(w1, w2, v1, v2);

                BLStatistic.Insert(w1.ID, w1.Skills);
                BLStatistic.Insert(w2.ID, w2.Skills);
                BLStatistic.Insert(v1.ID, v1.Skills);
                BLStatistic.Insert(v2.ID, v2.Skills);

                PlayerDao.Update(w1);
                PlayerDao.Update(w2);
                PlayerDao.Update(v1);
                PlayerDao.Update(v2);
            }
            MatchDao.Update(match);
            //}
        }
コード例 #5
0
        public HttpResponseMessage Update([FromBody] Player player, int playerId)
        {
            //if (Authentication.getInstance().isAuthenticateWithHeader(Request))
            //{
            IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database);

            Player pl = PlayerDao.FindById(player.ID);

            Player p = new Player(playerId, player.isAdmin, player.FirstName, player.LastName,
                                  player.Nickname, player.Skills, pl.PhotoPath, player.Password, player.isMonday,
                                  player.isTuesday, player.isWednesday, player.isThursday, player.isFriday, player.isSaturday);
            var boo = PlayerDao.Update(p);

            if (boo)
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Conflict));
            }

            //}
        }