public AccountInformation CreateNewAccountWithFacebook(string OAuthId, string email)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var SecrectCode = Guid.NewGuid().ToString();

                dctx.Accounts.Add(new Account
                {
                    Points = 0,
                    Email = email,
                    OAuthId = OAuthId,
                    GuestAccounts = new List<GuestAccount>()
                    {
                        new GuestAccount
                        {
                            SecretCode = SecrectCode
                        }
                    }
                });
                dctx.SaveChanges();

                return new AccountInformation()
                {
                    SecretCode = SecrectCode,
                    OAuthId = OAuthId,
                };
            }
        }
        public IEnumerable<RewardGroupInformation> GetRewardGroup()
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var qry = dctx.RewardGroups.Select(it => new RewardGroupInformation
                {
                    Id = it.Id,
                    RequestPoints = it.RequestPoints,
                    ExpiredDate = it.ExpiredDate,
                    RewardInfo = it.Rewards.Select(reward => new RewardInformation
                    {
                        Id = reward.Id,
                        Name = reward.Name,
                        Description = reward.Description,
                        Amount = reward.Amount,
                        RemainingAmount = reward.RemainingAmount.HasValue ? reward.RemainingAmount.Value : 0,
                        ImagePath = reward.ImagePath,
                        ThumbnailPath = reward.ThumbnailPath,
                        RewardGroupId = reward.RewardGroupId,
                    })
                }).ToList();

                return qry;
            }
        }
        public AccountInformation CreateAccount()
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var SecrectCode = Guid.NewGuid().ToString();

                dctx.Accounts.Add(new Account
                {
                    Points = 0,
                    GuestAccounts = new List<GuestAccount>()
                    {
                        new GuestAccount
                        {
                            SecretCode = SecrectCode
                        }
                    }
                });
                dctx.SaveChanges();

                return new AccountInformation()
                {
                    SecretCode = SecrectCode,
                };
            }
        }
        public RewardGroupInformation GetRewardGroupById(int id)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var qry = dctx.RewardGroups.FirstOrDefault(it => it.Id == id);

                return new RewardGroupInformation
                {
                    Id = qry.Id,
                    RequestPoints = qry.RequestPoints,
                    ExpiredDate = qry.ExpiredDate,
                    RewardInfo = qry.Rewards.Select(reward => new RewardInformation
                    {
                        Id = reward.Id,
                        Name = reward.Name,
                        Description = reward.Description,
                        Amount = reward.Amount,
                        RemainingAmount = reward.RemainingAmount.HasValue ? reward.RemainingAmount.Value : 0,
                        ImagePath = reward.ImagePath,
                        ThumbnailPath = reward.ThumbnailPath,
                        RewardGroupId = reward.RewardGroupId,
                    })
                };
            }
        }
 public void SelectTicket(int rewardId, int ticketId, DateTime selectedDate)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var selectedTicket = dctx.Tickets.FirstOrDefault(it => it.Id == ticketId);
         selectedTicket.ManualSelectedDate = selectedDate;
         selectedTicket.SelectedRewardId = rewardId;
         dctx.SaveChanges();
     }
 }
 public void CancelSelectedTicket(int rewardId, int ticketId)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var selectedTicket = dctx.Tickets.FirstOrDefault(it => it.Id == ticketId);
         selectedTicket.ManualSelectedDate = null;
         selectedTicket.RandomSelectedDate = null;
         selectedTicket.SelectedRewardId = null;
         dctx.SaveChanges();
     }
 }
 public void CreateRewardGroup(RewardGroupInformation model)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         dctx.RewardGroups.Add(new RewardGroup
         {
             Id = model.Id,
             RequestPoints = model.RequestPoints,
             ExpiredDate = model.ExpiredDate
         });
         dctx.SaveChanges();
     }
 }
 public IEnumerable<WinnerInformation> GetAllWinners()
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         return dctx.Winners.Select(it => new WinnerInformation
         {
             Id = it.Id,
             AccountFullName = it.Account.DisplayName, 
             //AccountSecrectCode = it.Account.SecretCode, // TODO: Check this out
             ReferenceCode = it.ReferenceCode,
             RewardId = it.RewardId
         }).ToList();
     }
 }
        public IEnumerable<GuestAccountInformation> GetGuestAccountsByAccountId(int accountId)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.GuestAccounts.Where(it => it.AccountId == accountId);
                if (selectedAccount == null) return null;

                return selectedAccount.Select(it => new GuestAccountInformation
                {
                     Id = it.Id,
                     SecretCode = it.SecretCode,
                     AccountId = it.AccountId
                }).ToList();
            }
        }
Esempio n. 10
0
        public AccountInformation GetAccountById(int id)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts.Include("GuestAccounts").FirstOrDefault(it => it.Id == id && it.GuestAccounts.Any());
                if (selectedAccount == null) return null;

                return new AccountInformation
                {
                    Points = selectedAccount.Points,
                    OAuthId = selectedAccount.OAuthId,
                    Email = selectedAccount.Email,
                    VerifiedPhoneNumber = selectedAccount.VerifiedPhoneNumber,
                    SecretCode = selectedAccount.GuestAccounts.First().SecretCode
                };
            }
        }
Esempio n. 11
0
 public void SubmitSelectedWinner(int rewardId, DateTime approveDate)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         const int RequiredVerificationDigits = 10;
         var verificationCode = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, RequiredVerificationDigits).ToUpper();
         var rewardInfo = dctx.Tickets.Where(it => it.SelectedRewardId.HasValue);
         if (rewardInfo != null)
         {
             rewardInfo.ToList().ForEach(it => {
                 var selectedTicket = dctx.Tickets.FirstOrDefault(ticket => ticket.Id == it.Id);
                 var accountInfo = dctx.Accounts.FirstOrDefault(account => account.Id == selectedTicket.AccountId);
                 selectedTicket.ApproveWinnerDate = approveDate;
                 dctx.Winners.Add(new Winner
                 {
                     AccountId = accountInfo.Id,
                     RewardId = rewardId,
                     ReferenceCode = verificationCode
                 });
                 dctx.SaveChanges();
             });
         } 
     }
 }
Esempio n. 12
0
 public IEnumerable<LeagueInformation> GetAllLeagues()
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var result = dctx.FavoriteTeams
             .Select(it => new LeagueInformation
             {
                 TeamId = it.Id,
                 LeagueName = it.LeagueName,
                 TeamName = it.TeamName
             }).ToList();
         return result;
     }
 }
Esempio n. 13
0
 public IEnumerable<RewardInformation> GetRewardsByIds(IEnumerable<int> ids)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var result = dctx.Rewards
             .Where(it => ids.Contains(it.Id))
             .Select(it => new RewardInformation
             {
                 Id = it.Id,
                 Amount = it.Amount,
                 Description = it.Description,
                 ImagePath = it.ImagePath,
                 Name = it.Name,
                 RemainingAmount = it.RemainingAmount.HasValue ? it.RemainingAmount.Value : 0,
                 RewardGroupId = it.RewardGroupId,
                 ThumbnailPath = it.ThumbnailPath
             }).ToList();
         return result;
     }
 }
Esempio n. 14
0
        public void TieFacbookWithFacebookData(string secrectCode, string OAuthId)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedFacebookAccount = dctx.Accounts.FirstOrDefault(it => it.OAuthId.Equals(OAuthId, StringComparison.CurrentCultureIgnoreCase));
                var selectedGuest = dctx.GuestAccounts.FirstOrDefault(it => it.SecretCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase));

                selectedGuest.AccountId = selectedFacebookAccount.Id;
                dctx.SaveChanges();
            }
        }
Esempio n. 15
0
        public void UpdateGuessResult(int guessMatchId, bool isGuessCorrect, int gotPoints)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedGuessMatch = dctx.GuessMatches.FirstOrDefault(it => it.Id == guessMatchId);
                if (selectedGuessMatch == null) return;

                selectedGuessMatch.IsWinner = isGuessCorrect;
                selectedGuessMatch.WinnerPoints = gotPoints;
                dctx.SaveChanges();
            }
        }
Esempio n. 16
0
 public void RequestConfirmPhoneNumber(RequestConfirmPhoneNumberRequest request, string verificationCode)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var newData = new PhoneVerification
         {
             PhoneNumber = request.PhoneNo,
             UserId = request.UserId,
             VerificationCode = verificationCode
         };
         dctx.PhoneVerifications.Add(newData);
         dctx.SaveChanges();
     }
 }
Esempio n. 17
0
        public void EditRewardGroup(int id, RewardGroupInformation model)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var qry = dctx.RewardGroups.FirstOrDefault(it => it.Id == model.Id);
                qry.Id = model.Id;
                qry.RequestPoints = model.RequestPoints;
                qry.ExpiredDate = model.ExpiredDate;

                dctx.SaveChanges();
            }
        }
Esempio n. 18
0
        public void SetFavoriteTeam(SetFavoriteTeamRequest request)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.GuestAccounts
                .Any(guestAccount => guestAccount.SecretCode.Equals(request.UserId, StringComparison.CurrentCultureIgnoreCase)));
                if (selectedAccount == null) return;

                var selectedTeam = dctx.FavoriteTeams.FirstOrDefault(it => it.Id == request.SelectedTeamId);
                if (selectedTeam == null) return;

                selectedAccount.FavoriteTeam = selectedTeam;
                dctx.SaveChanges();
            }
        }
Esempio n. 19
0
        public void ChargeFromBuyTicket(string secrectCode, int requiredPoints)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.GuestAccounts
                .Any(guestAccount => guestAccount.SecretCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase)));
                if (selectedAccount == null) return;

                selectedAccount.Points -= requiredPoints;
                dctx.SaveChanges();
            }
        }
Esempio n. 20
0
        public AccountInformation GetAccountBySecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return null;

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .Include("Tickets")
                    .Where(it => it.GuestAccounts.Any(guestAccount => guestAccount.SecretCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase)))
                    .FirstOrDefault();
                if (selectedAccount == null) return null;

                var currentRewardGroup = Facades.FacadeRepository.Instance.RewardDataAccess.GetRewardGroup()
                    .OrderByDescending(it => it.ExpiredDate)
                    .FirstOrDefault();

                var currentOrderedCoupon = selectedAccount.Tickets
                    .Where(it => it.RewardGroupId == currentRewardGroup.Id)
                    .Count();

                return new AccountInformation
                {
                    MaximumGuessAmount = 5, // HACK: Maximum guess amount
                    CurrentOrderedCoupon = currentOrderedCoupon,
                    Points = selectedAccount.Points,
                    SecretCode = secrectCode,
                    OAuthId = selectedAccount.OAuthId,
                    Email = selectedAccount.Email,
                    VerifiedPhoneNumber = selectedAccount.VerifiedPhoneNumber
                };
            }
        }
Esempio n. 21
0
        public VerificationPhoneInformation GetVerificationPhoneByVerificationCode(string userId, string verificationCode)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var result = dctx.PhoneVerifications
                    .Where(it => it.UserId.Equals(userId, StringComparison.CurrentCultureIgnoreCase))
                    .Where(it => it.VerificationCode.Equals(verificationCode, StringComparison.CurrentCultureIgnoreCase))
                    .Select(it => new VerificationPhoneInformation
                    {
                        Id = it.Id,
                        UserId = it.UserId,
                        PhoneNumber = it.PhoneNumber,
                        CompletedDate = it.CompletedDate,
                        VerificationCode = it.VerificationCode
                    }).FirstOrDefault();

                return result;
            }
        }
Esempio n. 22
0
        public AccountInformation GetAccountByOAuthId(string OAuthId)
        {
            var isArgumentValid = !string.IsNullOrEmpty(OAuthId);
            if (!isArgumentValid) return null;

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .FirstOrDefault(it => it.OAuthId.Equals(OAuthId, StringComparison.CurrentCultureIgnoreCase));
                if (selectedAccount == null) return null;

                return new AccountInformation
                {
                    Points = selectedAccount.Points,
                    OAuthId = selectedAccount.OAuthId,
                    Email = selectedAccount.Email,
                    VerifiedPhoneNumber = selectedAccount.VerifiedPhoneNumber,
                    SecretCode = selectedAccount.GuestAccounts.First().SecretCode
                };
            }
        }
Esempio n. 23
0
        public void VerifyPhoneSuccess(string userId, string phoneNo, string verificationCode)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedVerification = dctx.PhoneVerifications
                    .Where(it => it.UserId.Equals(userId, StringComparison.CurrentCultureIgnoreCase))
                    .Where(it => it.VerificationCode.Equals(verificationCode, StringComparison.CurrentCultureIgnoreCase))
                    .FirstOrDefault();
                if (selectedVerification == null) return;

                var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.GuestAccounts
                .Any(guestAccount => guestAccount.SecretCode.Equals(userId, StringComparison.CurrentCultureIgnoreCase)));
                if (selectedAccount == null) return;

                selectedVerification.CompletedDate = DateTime.Now;
                selectedAccount.VerifiedPhoneNumber = phoneNo;
                dctx.SaveChanges();
            }
        }
Esempio n. 24
0
 public void UpdateAccount(AccountInformation accountInfo)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.GuestAccounts
         .Any(guestAccount => guestAccount.SecretCode.Equals(accountInfo.SecretCode, StringComparison.CurrentCultureIgnoreCase)));
         if (selectedAccount != null)
         {
             selectedAccount.OAuthId = accountInfo.OAuthId;
             selectedAccount.Email = accountInfo.Email;
             selectedAccount.VerifiedPhoneNumber = accountInfo.VerifiedPhoneNumber;
             selectedAccount.Points = accountInfo.Points;
             dctx.SaveChanges();
         }
     }
 }
Esempio n. 25
0
        public void UpdateAccountPoints(int accountId, int additionPoints)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts.FirstOrDefault(it => it.Id == accountId);
                if (selectedAccount == null) return;

                selectedAccount.Points += additionPoints;
                dctx.SaveChanges();
            }
        }
Esempio n. 26
0
 public IEnumerable<WinnerInformation> GetWinnersByUserId(string userId)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var result = dctx.Winners
             .Where(it => it.Account.GuestAccounts.Any(guestAccount => guestAccount.SecretCode.Equals(userId, StringComparison.CurrentCultureIgnoreCase)))
             .Select(it => new WinnerInformation
             {
                 Id = it.Id,
                 AccountFullName = it.Account.DisplayName,
                 AccountSecrectCode = userId,
                 ReferenceCode = it.ReferenceCode,
                 RewardId = it.RewardId
             }).ToList();
         return result;
     }
 }
Esempio n. 27
0
        public void TieFacbookWithLocalData(string secrectCode, string OAuthId)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedFacebookAccount = dctx.Accounts.FirstOrDefault(it => it.OAuthId.Equals(OAuthId, StringComparison.CurrentCultureIgnoreCase));
                if (selectedFacebookAccount == null) return;
                var selectedGuestAccount = dctx.GuestAccounts.FirstOrDefault(it => it.SecretCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase)).Account;
                if (selectedGuestAccount == null) return;

                selectedGuestAccount.OAuthId = selectedFacebookAccount.OAuthId;
                selectedFacebookAccount.OAuthId = null;
                var guestAccout = selectedFacebookAccount.GuestAccounts.ToList();
                guestAccout.ForEach(it => it.AccountId = selectedGuestAccount.Id);

                dctx.SaveChanges();
            }
        }
Esempio n. 28
0
        public IEnumerable<GuessMatchInformation> GetGuessMatchsByMatchId(int matchId)
        {
            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedMatch = dctx.Matches
                    .Include("GuessMatches.Account")
                    .Where(it => it.Id == matchId)
                    .FirstOrDefault();
                if (selectedMatch == null) return Enumerable.Empty<GuessMatchInformation>();

                var result = selectedMatch.GuessMatches
                    .Select(it => new GuessMatchInformation
                    {
                        Id = it.Id,
                        AccountId = it.AccountId,
                        GuessTeamId = it.GuessTeamId,
                        MatchId = it.MatchId,
                        PredictionPoints = it.PredictionPoints
                    }).ToList();

                return result;
            }
        }
Esempio n. 29
0
        public IEnumerable<GuessMatchInformation> GetGuessMatchsByAccountSecrectCode(string secrectCode)
        {
            var isArgumentValid = !string.IsNullOrEmpty(secrectCode);
            if (!isArgumentValid) return Enumerable.Empty<GuessMatchInformation>();

            using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
            {
                var selectedAccount = dctx.Accounts
                    .Include("GuessMatches")
                    .Where(it => it.GuestAccounts.Any(guestAccount => guestAccount.SecretCode.Equals(secrectCode, StringComparison.CurrentCultureIgnoreCase)))
                    .FirstOrDefault();
                if (selectedAccount == null) return Enumerable.Empty<GuessMatchInformation>();

                var result = selectedAccount.GuessMatches
                    .Select(it => new GuessMatchInformation
                    {
                        Id = it.Id,
                        AccountSecrectCode = secrectCode,
                        GuessTeamId = it.GuessTeamId,
                        MatchId = it.MatchId,
                        PredictionPoints = it.PredictionPoints
                    }).ToList();

                return result;
            }
        }
Esempio n. 30
0
 public RewardInformation GetRewardsById(int id)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var result = dctx.Rewards.FirstOrDefault(it => it.Id == id);
         if (result == null) return null;
         return new RewardInformation
         {
             Id = result.Id,
             Amount = result.Amount,
             Description = result.Description,
             ImagePath = result.ImagePath,
             Name = result.Name,
             RemainingAmount = result.RemainingAmount.HasValue ? result.RemainingAmount.Value : 0,
             RewardGroupId = result.RewardGroupId,
             ThumbnailPath = result.ThumbnailPath
         };
     }
 }