Пример #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();
 }
Пример #2
0
 public IHttpActionResult Follow()
 {
     var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault());
     var tId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("teamId").FirstOrDefault());
     var uRepo = new UserRepository();
     var tRepo = new TeamRepository();
     if (!(uRepo.ContainsId(uId) && tRepo.ContainsId(tId)))
         return NotFound();
     var u = uRepo.GetById(uId);
     var t = tRepo.GetById(tId);
     u.FollowedTeams.Add(t);
     uRepo.SaveOrUpdate(u);
     return Ok();
 }
Пример #3
0
 public IHttpActionResult UnFollow()
 {
     var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault());
     var tId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("teamId").FirstOrDefault());
     var uRepo = new UserRepository();
     var tRepo = new TeamRepository();
     if (!(uRepo.ContainsId(uId) && tRepo.ContainsId(tId)))
         return NotFound();
     var u = uRepo.GetById(uId);
     var t = tRepo.GetById(tId);
     if (u.FollowedTeams.Where(x => x.Id == t.Id).Take(1).Count() > 0)
     {
         u.FollowedTeams.Remove(t);
         t.FollowedBy.Remove(u);
     }
     uRepo.SaveOrUpdate(u);
     return Ok();
 }