Exemplo n.º 1
0
 public IHttpActionResult Bet([FromBody]dynamic value)
 {
     var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault());
     var mId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("matchId").FirstOrDefault());
     var homeScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("homeScore").FirstOrDefault());
     var awayScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("awayScore").FirstOrDefault());
     var mRepo = new MatchRepository();
     if (!mRepo.ContainsId(mId))
         return NotFound();
     var uRepo = new UserRepository();
     if (!uRepo.ContainsId(uId))
         return NotFound();
     var brepo = new BetRepository();
     if (brepo.ContainsBet(mId, uId))
     {
         var b = brepo.GetByMatchAndUserIds(mId, uId);
         b.HomeTeamScore = homeScore;
         b.AwayTeamScore = awayScore;
         brepo.SaveOrUpdate(b);
     }
     else
     {
         var b = new Bet();
         b.AwayTeamScore = awayScore;
         b.HomeTeamScore = homeScore;
         b.Match = mRepo.GetById(mId);
         b.User = uRepo.GetById(uId);
         brepo.SaveOrUpdate(b);
     }
     return Ok();
 }
Exemplo n.º 2
0
        public IHttpActionResult Bet([FromBody] dynamic value)
        {
            var uId       = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault());
            var mId       = Int32.Parse(HttpContext.Current.Request.Form.GetValues("matchId").FirstOrDefault());
            var homeScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("homeScore").FirstOrDefault());
            var awayScore = Int32.Parse(HttpContext.Current.Request.Form.GetValues("awayScore").FirstOrDefault());
            var mRepo     = new MatchRepository();

            if (!mRepo.ContainsId(mId))
            {
                return(NotFound());
            }
            var uRepo = new UserRepository();

            if (!uRepo.ContainsId(uId))
            {
                return(NotFound());
            }
            var brepo = new BetRepository();

            if (brepo.ContainsBet(mId, uId))
            {
                var b = brepo.GetByMatchAndUserIds(mId, uId);
                b.HomeTeamScore = homeScore;
                b.AwayTeamScore = awayScore;
                brepo.SaveOrUpdate(b);
            }
            else
            {
                var b = new Bet();
                b.AwayTeamScore = awayScore;
                b.HomeTeamScore = homeScore;
                b.Match         = mRepo.GetById(mId);
                b.User          = uRepo.GetById(uId);
                brepo.SaveOrUpdate(b);
            }
            return(Ok());
        }