public List <UserEL> CalculateAllUserPoints(int matchId) { try { //Display all user with points UserEL tmpUserEL; List <UserEL> lstUserEL = new List <UserEL>(); var tempMD = objUserDB.GetMatchDetailsbyMatchId(matchId); var listUserId = (tempMD.Select(t => t.UserId).ToList()).Distinct(); foreach (var a in listUserId) { tmpUserEL = new UserEL(); tmpUserEL.userId = (int)a.Value; tmpUserEL.userName = tempMD.Where(t => t.UserId == a.Value).Select(t => t.ref_UserDetails.UserName).FirstOrDefault(); tmpUserEL.lstPlayerId = tempMD.Where(t => t.UserId == a).Select(t => (int)t.PlayerId).ToList(); tmpUserEL.UserPoints = objUserBL.GetUserPoints(tmpUserEL.lstPlayerId, matchId); tmpUserEL.userRank = 1; lstUserEL.Add(tmpUserEL); } lstUserEL = UserRanking(lstUserEL); return(lstUserEL); } catch (Exception ex) { throw ex; } }
public UserLoginResponse Login(UserLoginRequest request) { UserLoginResponse userLoginResponse = new UserLoginResponse(); userLoginResponse.Message = "Incorrect Userid or Password. Please try again."; if (String.IsNullOrEmpty(request.UserNameOREmail) || String.IsNullOrEmpty(request.PasswordHash)) { userLoginResponse.Message = "Please pass all mandatory fields."; return(userLoginResponse); } UserEL userEL = new UserEL(); userEL.Username = request.UserNameOREmail; userEL.Password = request.PasswordHash; UserEL userData = userHelper.LoginUser(userEL); if (userData.Username != null) { userLoginResponse.Message = "User logged in successfully."; userLoginResponse.Token = userData.Token; userLoginResponse.UserID = userData.StoreUserID; userLoginResponse.FullName = userData.StoreName; userLoginResponse.IsLoggedIn = userLoginResponse.IsSuccess = true; userLoginResponse.PushToken = userData.DeviceID; return(userLoginResponse); } else { userLoginResponse.IsLoggedIn = userLoginResponse.IsSuccess = false; return(userLoginResponse); } }
public UpdateDeviceTokenResponse UpdatePushToken(UpdateDeviceTokenRequest userRequest) { UpdateDeviceTokenResponse updateTokenResponse = new UpdateDeviceTokenResponse(); updateTokenResponse.IsSuccess = false; updateTokenResponse.Message = "Update device push token unsuccessful"; try { if (!string.IsNullOrEmpty(userRequest.AuthToken) && !string.IsNullOrEmpty(userRequest.DevicePushToken) && !string.IsNullOrEmpty(userRequest.DeviceType) ) { UserEL userPushData = new UserEL(); userPushData.DeviceID = userRequest.DevicePushToken; userPushData.DeviceType = userRequest.DeviceType; userPushData.AuthToken = userRequest.AuthToken; userHelper.UpdateUserToken(userPushData); } else { updateTokenResponse.Message = "Please pass value of all mandatory fields"; } } catch (Exception ex) { updateTokenResponse.Message = "An error occurred while update device push token."; } return(updateTokenResponse); }
public RegisterStoreResponse Register(RegisterStoreRequest request) { RegisterStoreResponse registerStoreResponse = new RegisterStoreResponse(); registerStoreResponse.Message = "Store not registered successfully."; if (String.IsNullOrEmpty(request.UserInfo.Username) || String.IsNullOrEmpty(request.UserInfo.Password) || String.IsNullOrEmpty(request.UserInfo.Email)) { registerStoreResponse.Message = "Please pass all mandatory fields."; return(registerStoreResponse); } if (new Helper().IsEmailExist(request.UserInfo.Email) || new Helper().IsUserNameExist(request.UserInfo.Username)) { registerStoreResponse.Message = "Username of Email already exist."; return(registerStoreResponse); } UserEL userEL = new UserEL(); userEL = MapperUtility.MapTo(request.UserInfo, userEL); if (userHelper.RegisterUser(userEL)) { registerStoreResponse.Message = "Registration successfully completed."; registerStoreResponse.IsLoggedIn = registerStoreResponse.IsSuccess = true; return(registerStoreResponse); } else { registerStoreResponse.Message = "Some error occured."; return(registerStoreResponse); } }
public bool RegisterUser(UserEL user) { bool isUserRegistered = false; try { StoreUser storeUser = new StoreUser(); storeUser = MapperUtility.MapTo(user, storeUser); using (uow = new UnitOfWork.UnitOfWork()) { storeUser.Password = EncryptionHelper.Encrypt(storeUser.Password); uow.StoreUserRepository.Insert(storeUser); uow.Save(); isUserRegistered = true; } } catch { isUserRegistered = false; } return(isUserRegistered); }
public UserEL LoginUser(UserEL userElData) { UserEL user = new UserEL(); string PasswordHash = EncryptionHelper.Encrypt(userElData.Password); using (uow = new UnitOfWork.UnitOfWork()) { StoreUser storeUserData = uow.StoreUserRepository.Get().Where(u => PasswordHash.Equals(u.Password) && userElData.Username.Equals(u.Username) ).FirstOrDefault(); string token; if (storeUserData != null) { AuthenticationToken existingToken = uow.AuthenticationTokenRepository.Get(). Where(auth => auth.FkUserID.Equals(storeUserData.StoreUserID)) .FirstOrDefault(); if (existingToken != null) { token = existingToken.Token; } else { AuthenticationToken authToken = new AuthenticationToken(); authToken.FkUserID = storeUserData.StoreUserID; token = authToken.Token = Guid.NewGuid().ToString().Replace("-", ""); authToken.CreatedDate = System.DateTime.UtcNow; uow.AuthenticationTokenRepository.Insert(authToken); uow.Save(); } user = MapperUtility.MapTo(storeUserData, user); user.Token = token; } } return(user); }
public List <UserEL> UserRanking(List <UserEL> lstuserdetails) { UserEL tmp; List <UserEL> lstUser = new List <UserEL>(); int i = 1; int j = 0; lstuserdetails = lstuserdetails.OrderByDescending(t => t.UserPoints).ToList(); foreach (var t in lstuserdetails) { tmp = new UserEL(); if (i <= lstuserdetails.Count) { if (j > 0 && lstuserdetails[j - 1].UserPoints == lstuserdetails[j].UserPoints) { if (i != 1) { i--; } tmp.userRank = i; } else { tmp.userRank = i; } tmp.userId = t.userId; tmp.userName = t.userName; tmp.lstPlayerId = t.lstPlayerId; tmp.UserPoints = t.UserPoints; i++; j++; } lstUser.Add(tmp); } return(lstUser); }
public bool UpdateUserToken(UserEL user) { bool isTokenUpdated = false; if (user.AuthToken != null) { using (uow = new UnitOfWork.UnitOfWork()) { AuthenticationToken authToken = new Helper.Helper().GetAuthenticationToken(user.AuthToken); StoreUser existingUser = null; existingUser = uow.StoreUserRepository.Get().Where(u => u.StoreUserID.Equals(authToken.FkUserID)).FirstOrDefault(); #region Get Existing User if (existingUser != null) { existingUser.DeviceID = user.DeviceID; existingUser.DeviceType = user.DeviceType; uow.StoreUserRepository.Update(existingUser); uow.Save(); isTokenUpdated = true; return(isTokenUpdated); } else { isTokenUpdated = false; } #endregion } } else { isTokenUpdated = false; } return(isTokenUpdated); }