Пример #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 ManageController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
 {
     UserManager = userManager;
     SignInManager = signInManager;
     passwordHasher = new PasswordHasher();
     userRepository = new UserRepository();
 }
Пример #3
0
 public ActionResult Index()
 {
     MatchRepository _repository = new MatchRepository();
     UserRepository userRepository = new UserRepository();
     if(System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
     {
         IEnumerable<Match> tempFollowed =  _repository.GetMatchesOfFollowedTeams(userRepository.GetByName(System.Web.HttpContext.Current.User.Identity.Name).Id);
         ViewData["followedMatches"] = tempFollowed.OrderBy(o => o.Date).Reverse().ToList();
     }
     IEnumerable<Match> tempAll = cache.GetOrSet("home.allMatches", ()=>_repository.GetAll());
     ViewData["allMatches"] = tempAll.OrderBy(o => o.Date).Reverse().ToList();
     return View();
 }
Пример #4
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();
 }
Пример #5
0
 private static void Main(string[] args)
 {
     IUserRepository users = new UserRepository();
     users.Save(new User { Id = 0, Name = "first" });
     users.Save(new User { Id = 1, Name = "second" });
     User secondUser = users.Find(1);
     Console.WriteLine(secondUser.Name);
     List<User> allUsers = users.GetAll();
     foreach (User user in allUsers)
     {
         Console.WriteLine(user.Name);
     }
     Console.ReadLine();
 }
Пример #6
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();
 }
Пример #7
0
        public ServiceResponse<User> GetUser(ServiceRequest<string> userName)
        {
            // simulate Usererror 
            if (String.IsNullOrEmpty(userName.Value))
            {
                return new ServiceResponse<User>()
                {
                    Result = ServiceResult.Failed,
                    ErrorCodes = ErrorCodes.InvalidName
                };
            }

            // simulate Systemerror
            if (userName.Value == "Tester0")
            {
                return new ServiceResponse<User>()
                {
                    Result = ServiceResult.Fatal,
                    Exception = new ArgumentException()
                };
                // or should I throw it???
            }

            // everything works
            UserRepository rep = new UserRepository();
            User result = rep.GetUsers().ToList().Where(x => x.Name == userName.Value).SingleOrDefault();
            // nothing found
            if (result == null)
            {
                return new ServiceResponse<User>() { Result = ServiceResult.Failed, ErrorCodes = ErrorCodes.NothingFound };
            }
            else
            {
                return new ServiceResponse<User>() { Value = result, Result = ServiceResult.Succeeded };
            }
        }
Пример #8
0
 public ManageController()
 {
     passwordHasher = new PasswordHasher();
     userRepository = new UserRepository();
 }
Пример #9
0
 public AccountController()
 {
     passwordHasher = new PasswordHasher();
     userRepository = new UserRepository();
 }