/// <summary> /// Function to delete COD /// </summary> /// <returns>void</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/21/2015 /// </devdoc> public static void DeleteCOD(int id) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { //Delete COD traceLog.AppendLine("Start:DeleteCOD() with challenge Id-" + id); List <tblChallengeofTheDayQueue> objChallengeofTheDayQueue = _dbContext.ChallengeofTheDayQueue.Where(ce => ce.QueueId == id).ToList(); if (objChallengeofTheDayQueue != null) { _dbContext.ChallengeofTheDayQueue.RemoveRange(objChallengeofTheDayQueue); _dbContext.SaveChanges(); } } catch { throw; } finally { traceLog.AppendLine("DeleteCOD end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get Exercise Upload History /// </summary> /// <returns></returns> public static List <ViewExerciseVM> GetExerciseUploadHistory() { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: GetExecisesList---- " + DateTime.Now.ToLongDateString()); List <ViewExerciseVM> exerlistlist = dataContext.ExerciseUploadHistory .Select(exe => new ViewExerciseVM { TeamId = exe.TeamId, TrainerId = exe.TrainerId, ExerciseName = string.IsNullOrEmpty(exe.ExerciseName) ?exe.FailedVideoName : exe.ExerciseName , CreatedDate = exe.CreatedDate, Index = exe.Index, }).OrderByDescending(ch => ch.CreatedDate).ToList(); return(exerlistlist); } catch { throw; } finally { traceLog.AppendLine("End GetExecisesList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to delete sponsor challenge /// </summary> /// <returns>void</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/21/2015 /// </devdoc> public static void DeleteSponsorChallenge(int Id) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: DeleteSponsorChallenge---- " + DateTime.Now.ToLongDateString()); //Delete sponser CHallenge List <tblSponsorChallengeQueue> objTrainerChallenge = _dbContext.TrainerChallenge.Where(ce => ce.QueueId == Id).ToList(); if (objTrainerChallenge != null) { _dbContext.TrainerChallenge.RemoveRange(objTrainerChallenge); } _dbContext.SaveChanges(); } catch { throw; } finally { traceLog.AppendLine("DeleteSponsorChallenge end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
public static void UpdateLastLogin() { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: UpdateLastLogin"); if (System.Web.HttpContext.Current.Session != null) { int credentialId = Convert.ToInt32(System.Web.HttpContext.Current.Session["CredentialId"]); tblCredentials credential = _dbContext.Credentials.Where(m => m.Id == credentialId).FirstOrDefault(); credential.LastLogin = DateTime.Now; _dbContext.SaveChanges(); } } catch { throw; } finally { traceLog.AppendLine("UpdateLastLogin end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to delete current user token /// </summary> /// <param></param> /// <returns>bool</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 05/19/2015 /// </devdoc> public static bool DeleteCurrentUserToken() { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { tblUserToken userToken = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: DeleteCurrentUserToken"); string token = Thread.CurrentPrincipal.Identity.Name; bool flag = false; userToken = _dbContext.UserToken.Remove(_dbContext.UserToken.FirstOrDefault(u => u.Token.Equals(token))); _dbContext.SaveChanges(); if (userToken != null) { flag = true; } return(flag); } finally { traceLog.AppendLine("End: DeleteCurrentUserToken --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); userToken = null; } } }
/// <summary> /// Function to get Credentials object of Current User on the basis of Token Id /// </summary> /// <param name="token">string</param> /// <returns>Credentials</returns> public static Credentials GetUserId(string token) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { StringBuilder traceLog = null; Credentials objCredential = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetUserId"); objCredential = (from c in _dbContext.Credentials join ut in _dbContext.UserToken on c.Id equals ut.UserId where ut.Token == token select new Credentials { Id = c.Id, UserId = c.UserId, UserType = c.UserType, DeviceID = ut.TokenDevicesID, DeviceType = ut.DeviceType }).FirstOrDefault(); return(objCredential); } finally { traceLog.AppendLine("End: GetUserId --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; objCredential = null; } } }
/// <summary> /// Function delete featured activity /// </summary> /// <returns>int</returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/21/2015 /// </devdoc> public static void DeleteFeaturedActivity(int id) { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: DeleteFeaturedActivity"); tblFeaturedActivityQueue featuredActivityQueue = dataContext.FeaturedActivityQueue.Where(ce => ce.Id == id).FirstOrDefault(); if (featuredActivityQueue != null) { dataContext.FeaturedActivityQueue.Remove(featuredActivityQueue); dataContext.SaveChanges(); } } catch { throw; } finally { traceLog.AppendLine("DeleteActivity end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to get activities from database for displaying /// </summary> /// <returns>List<ViewActivitiesVM></returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/04/2015 /// </devdoc> public static List <ViewActivitiesVM> GetActivities() { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: GetTrainers for retrieving challenges from database "); List <ViewActivitiesVM> filterdActivities = new List <ViewActivitiesVM>(); DateTime today = DateTime.Now.Date; List <ViewActivitiesVM> objActivity = (from A in dataContext.Activity join C in dataContext.Credentials on A.TrainerId equals C.Id join S in dataContext.States on A.State equals S.StateCode join Ct in dataContext.Cities on A.City equals Ct.CityId join T in dataContext.Trainer on C.UserId equals T.TrainerId orderby A.ModifiedDate descending select new ViewActivitiesVM { ActivityId = A.ActivityId, NameOfActivity = A.NameOfActivity, TrainerName = T.FirstName + " " + T.LastName, DateofEvent = A.DateOfEvent, Location = Ct.CityName + ", " + S.StateName }).ToList <ViewActivitiesVM>(); foreach (var item in objActivity) { tblFeaturedActivityQueue featuredActivityQueue = dataContext.FeaturedActivityQueue.FirstOrDefault(c => c.ActivityId == item.ActivityId); /*add featured activity in queue to display on dashborad*/ if (featuredActivityQueue != null) { if ((featuredActivityQueue.StartDate <= today && featuredActivityQueue.EndDate <= today) || (featuredActivityQueue.StartDate >= today && featuredActivityQueue.EndDate >= today)) { ViewActivitiesVM filterdActivity = new ViewActivitiesVM(); filterdActivity = item; filterdActivities.Add(filterdActivity); } } else { ViewActivitiesVM filterdActivity = new ViewActivitiesVM(); filterdActivity = item; filterdActivities.Add(filterdActivity); } } return(filterdActivities); } catch { throw; } finally { traceLog.AppendLine("GetTrainers end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to check old password is correct or not /// </summary> /// <param></param> /// <returns>bool</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 07/24/2015 /// </devdoc> private static bool IsOldPasswordCorrect(string oldPwd, int credId) { StringBuilder traceLog = null; bool flag = false; EncryptDecrypt objEncrypt = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { tblCredentials objCredential = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: IsOldPasswordCorrect"); objEncrypt = new EncryptDecrypt(); string encPwd = objEncrypt.EncryptString(oldPwd); objCredential = _dbContext.Credentials.Where(crd => crd.Id == credId && crd.Password == encPwd).FirstOrDefault(); if (objCredential != null) { flag = true; } return(flag); } finally { objEncrypt.Dispose(); traceLog.AppendLine("End: IsOldPasswordCorrect --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); objCredential = null; } } }
/// <summary> /// Remove notification incash fail to send notification /// </summary> /// <param name="userNotificationID"></param> /// <returns></returns> public static bool RemoveUserNotification(long userNotificationID) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { StringBuilder traceLog = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetSaveDevicesNotification"); var objdeviceNft = _dbContext.UserNotifications.Where(nt => nt.NotificationID == userNotificationID).FirstOrDefault(); _dbContext.UserNotifications.Remove(objdeviceNft); _dbContext.SaveChanges(); return(true); } catch { return(false); } finally { traceLog.AppendLine("End: GetSaveDevicesNotification --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Update Device Token And Type based on AuthToken /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UpdateDeviceTokenAndType(DeviceTokenVM model) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { StringBuilder traceLog = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: UpdateDeviceTokenAndType()"); if (!string.IsNullOrEmpty(model.AuthToken)) { var userToken = _dbContext.UserToken.Where(dn => dn.Token.Equals(model.AuthToken.Trim())).FirstOrDefault(); if (userToken != null) { userToken.TokenDevicesID = model.DeviceToken; userToken.DeviceType = model.DeviceType.ToString(); _dbContext.SaveChanges(); return(true); } } return(false); } finally { traceLog.AppendLine("End: UpdateDeviceTokenAndType --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Check user notification Status /// </summary> /// <param name="userID"></param> /// <param name="devicesToken"></param> /// <param name="NotificationType"></param> /// <returns></returns> public static UserNotificationSettingVM GetNotificationStatus(int userID, string NotificationType, string deviceId, string devicesType) { using (LinksMediaContext dataContext = new LinksMediaContext()) { StringBuilder traceLog = null; UserNotificationSettingVM objUserNotificationVM = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetNotificationSattus()"); objUserNotificationVM = (from us in dataContext.UserNotificationSetting where us.UserCredId == userID && us.NotificationType == NotificationType && us.DeviceID == deviceId && us.DeviceType == devicesType select new UserNotificationSettingVM { DeviceID = us.DeviceID, IsNotify = us.IsNotify }).FirstOrDefault(); return(objUserNotificationVM); } catch { throw; } finally { traceLog.AppendLine("End: GetNotificationSattus --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> public static bool UTCPostMessage(UTCMessageVM model) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { StringBuilder traceLog = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: UTCPostMessage"); tblUTCPostMessage objUTCPostMessage = new tblUTCPostMessage { PostMessage = model.Message, PostDateTime = model.PostedDate }; _dbContext.UTCPostMessage.Add(objUTCPostMessage); _dbContext.SaveChanges(); return(true); } finally { traceLog.AppendLine("End: UTCPostMessage --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to authenticate User /// </summary> /// <param name="username">username</param> /// <param name="password">password</param> /// <returns>True/False</returns> public static bool ValidateUser(string username, string password, ref Credentials credential) { bool success = false; StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: Login, ValidateUser Method with Param UserName: "******"Index Start end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } return(success); }
/// <summary> /// Change Exercise Status /// </summary> /// <param name="exerciseId"></param> /// <param name="operationId"></param> /// <returns></returns> public static ExerciseStatusVM ChangeExerciseStatus(int exerciseId, int operationId) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { ExerciseStatusVM objExerciseStatusVM = new ExerciseStatusVM(); traceLog.AppendLine("Start: ChangeExerciseStatus---- " + DateTime.Now.ToLongDateString()); if (exerciseId > 0) { tblExercise exercise = dataContext.Exercise.Where(ex => ex.ExerciseId == exerciseId).FirstOrDefault(); switch (operationId) { case 1: { exercise.ExerciseStatus = 1; objExerciseStatusVM.OperationId = operationId; objExerciseStatusVM.OperationResultId = 1; } break; case 2: { exercise.ExerciseStatus = 2; objExerciseStatusVM.OperationId = operationId; objExerciseStatusVM.OperationResultId = 2; } break; case 3: { if (dataContext.CEAssociation.Any(ex => ex.ExerciseId == exerciseId)) { exercise.ExerciseStatus = 2; objExerciseStatusVM.OperationResultId = -1; } else { exercise.ExerciseStatus = 3; objExerciseStatusVM.OperationResultId = 1; } objExerciseStatusVM.OperationId = operationId; } break; } dataContext.SaveChanges(); } return(objExerciseStatusVM); } finally { traceLog.AppendLine("End ChangeExerciseStatus : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get DashBoard Activity Count /// </summary> /// <returns></returns> public static DashBoardActivityCount GetDashBoardActivityCount() { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { traceLog = new StringBuilder(); DashBoardActivityCount objDashBoardActivity = new DashBoardActivityCount(); try { traceLog.AppendLine("Start: GetDashBoardActivityCount()"); List <int> ChallengeSubTypeList = ChallengesBL.GetFitnessTestORWorkoutSubTypeId(ConstantHelper.constFittnessCommonSubTypeId); objDashBoardActivity.FitnessTestCount = dataContext.Challenge.Count(ch => !ch.IsDraft && ChallengeSubTypeList.Contains(ch.ChallengeSubTypeId)); objDashBoardActivity.ActiveFitnessTestCount = dataContext.Challenge.Count(ch => !ch.IsDraft && ch.IsActive && ChallengeSubTypeList.Contains(ch.ChallengeSubTypeId)); objDashBoardActivity.UserCount = dataContext.User.Count(); //objDashBoardActivity.PremiumUserCount = (from crd in dataContext.Credentials // where crd.UserType != Message.UserTypeTeam // && (crd.IOSSubscriptionStatus || crd.AndriodSubscriptionStatus) // select crd.Id // ).Distinct().Count(); objDashBoardActivity.PremiumUserCount = (from usr in dataContext.User join crd in dataContext.Credentials on usr.UserId equals crd.UserId where crd.UserType == Message.UserTypeUser && (crd.IOSSubscriptionStatus || crd.AndriodSubscriptionStatus) select crd.Id ).Distinct().Count(); objDashBoardActivity.TrainerCount = dataContext.Trainer.Count(); objDashBoardActivity.TeamCount = dataContext.Teams.Count(); objDashBoardActivity.WorkoutCount = dataContext.Challenge.Count(workt => !workt.IsDraft && workt.ChallengeSubTypeId == ConstantHelper.constWorkoutChallengeSubType); objDashBoardActivity.ActiveWorkoutCount = dataContext.Challenge.Count(workt => !workt.IsDraft && workt.IsActive && workt.ChallengeSubTypeId == ConstantHelper.constWorkoutChallengeSubType); objDashBoardActivity.ProgramCount = dataContext.Challenge.Count(y => !y.IsDraft && y.ChallengeSubTypeId == ConstantHelper.constProgramChallengeSubType); objDashBoardActivity.ActiveProgramCount = dataContext.Challenge.Count(y => !y.IsDraft && y.IsActive && y.ChallengeSubTypeId == ConstantHelper.constProgramChallengeSubType); objDashBoardActivity.ActivityCount = dataContext.Activity.Count(); return(objDashBoardActivity); } catch { throw; } finally { traceLog.AppendLine("GetDashBoardActivityCount end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get TrainerLibrary Sub CategoryList /// </summary> /// <param name="userId"></param> /// <param name="userType"></param> /// <param name="challengeTypeId"></param> /// <returns></returns> public static List <ChallengeCategory> GetTrainerLibrarySubCategoryList(int userId, string userType, int challengeTypeId) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: GetTrainerLibrarySubCategoryList---- " + DateTime.Now.ToLongDateString()); int trainerCredId = -1; // ChallengeTabVM objChallengeTabVM = new ChallengeTabVM(); if (userType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { trainerCredId = (from tr in dataContext.Trainer join crd in dataContext.Credentials on tr.TrainerId equals crd.UserId where crd.UserType == Message.UserTypeTrainer && tr.TrainerId == userId select crd.Id).FirstOrDefault(); } if (trainerCredId > 0 && challengeTypeId > 0) { List <int> categorylist = (from c in dataContext.Challenge join ct in dataContext.ChallengeCategoryAssociations on c.ChallengeId equals ct.ChallengeId where c.IsActive && c.TrainerId == trainerCredId && c.ChallengeSubTypeId == challengeTypeId orderby c.CreatedDate descending select ct.ChallengeCategoryId).Distinct().ToList(); var challengeCategoryList = (from cc in dataContext.ChallengeCategory where cc.ChallengeSubTypeId == challengeTypeId && categorylist.Contains(cc.ChallengeCategoryId) && cc.Isactive select new ChallengeCategory { ChallengeCategoryName = cc.ChallengeCategoryName, ChallengeCategoryId = cc.ChallengeCategoryId, ProgramTypeId = ConstantHelper.constProgramChallengeSubType }).OrderBy(cn => cn.ChallengeCategoryName).ToList(); return(challengeCategoryList); } return(null); } catch { throw; } finally { traceLog.AppendLine("End GetTrainerLibrarySubCategoryList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to authenticate user Token /// </summary> /// <param name="token">token</param> /// <returns>True/False</returns> public static bool ValidateToken(string token, string clientIPAddress) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { bool success = false; StringBuilder traceLog = null; tblUserToken userToken = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: Login, ValidateUserToken Method with Param token: " + token); userToken = _dbContext.UserToken.FirstOrDefault(t => t.Token == token && t.ClientIPAddress == clientIPAddress); if (userToken != null) { if (userToken.IsRememberMe) { success = true; } else { if (userToken.ExpiredOn > DateTime.Now) { if (!userToken.IsExpired) { success = true; userToken.ExpiredOn = DateTime.Now.AddMinutes(Convert.ToByte(ConfigurationManager.AppSettings["ExpireDuration"])); } } else { userToken.IsExpired = true; } } _dbContext.SaveChanges(); } return(success); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(false); } finally { traceLog.AppendLine("Index Start end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; userToken = null; } } }
/// <summary> /// /// </summary> /// <param name="credID"></param> /// <returns></returns> public static int GetMyFriendChallengeCount(int credID) { using (LinksMediaContext dataContext = new LinksMediaContext()) { StringBuilder traceLog = null; int pendingcount = 0; // List<PendingChallengeVM> listPendingChallenge = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetMyFriendChallengeCount-credID" + credID); List <PendingChallengeVM> listPendingChallenge = (from c in dataContext.Challenge join ctf in dataContext.ChallengeToFriends on c.ChallengeId equals ctf.ChallengeId join ct in dataContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId join crd in dataContext.Credentials on ctf.SubjectId equals crd.Id where c.IsActive && ctf.TargetId == credID && ctf.IsActive && ctf.IsPending && crd.UserType == Message.UserTypeUser orderby ctf.ChallengeDate descending select new PendingChallengeVM { ChallengeId = c.ChallengeId, SubjectId = ctf.SubjectId }).ToList(); // Remove the duplicate the pending challenges if (listPendingChallenge != null) { listPendingChallenge = listPendingChallenge.GroupBy(pl => new { pl.ChallengeId, pl.SubjectId }) .Select(grp => grp.FirstOrDefault()) .ToList(); } // Total count of pending queue if (listPendingChallenge != null) { pendingcount = listPendingChallenge.Count(); } return(pendingcount); } catch { throw; } finally { traceLog.AppendLine("End: GetMyFriendChallengeCount --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; //listPendingChallenge = null; } } }
/// <summary> /// Delete the old the authenication on same devices /// </summary> /// <param name="devicesId"></param> /// <param name="deviceUID"></param> /// <param name="devicesType"></param> /// <returns></returns> public static bool DeleteOtherUserTokensOnDevices(string devicesId, string devicesType) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { bool success = false; StringBuilder traceLog = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: DeleteOtherUserTokensOnDevices(), delete old existing token records: " + devicesId); if (!string.IsNullOrWhiteSpace(devicesType) && devicesType == DiviceTypeType.Android.ToString()) { string andriodDevicesType = DiviceTypeType.Android.ToString(); List <tblUserToken> userTokenlist = _dbContext.UserToken.Where(ut => ut.TokenDevicesID == devicesId && ut.DeviceType == andriodDevicesType).ToList(); /*delete accepted change by the user*/ if (userTokenlist != null) { _dbContext.UserToken.RemoveRange(userTokenlist); _dbContext.SaveChanges(); success = true; } } else if (!string.IsNullOrWhiteSpace(devicesType) && devicesType == DiviceTypeType.IOS.ToString()) { if (!string.IsNullOrWhiteSpace(devicesId)) { List <tblUserToken> userTokenlist = _dbContext.UserToken.Where(ut => ut.TokenDevicesID == devicesId).ToList(); /*delete accepted change by the user*/ if (userTokenlist != null) { _dbContext.UserToken.RemoveRange(userTokenlist); _dbContext.SaveChanges(); success = true; } } } } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); return(false); } finally { traceLog.AppendLine(" DeleteOtherUserTokensOnDevices end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } return(success); } }
/// <summary> /// Upadte or Save DevicesNotification count for user /// </summary> /// <param name="model"></param> /// <returns></returns> public static long SaveDevicesNotification(UserNotificationsVM model) { using (LinksMediaContext _dbContext = new LinksMediaContext()) { StringBuilder traceLog = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetSaveDevicesNotification"); int userCredetials = 0; var objCredentials = _dbContext.Credentials.Where(user => user.UserId == model.UserID && user.UserType.Equals(model.UserType, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (objCredentials != null) { userCredetials = objCredentials.Id; } if (userCredetials != model.ReceiverCredID && !_dbContext.UserNotifications.Any(f => f.SenderCredlID == userCredetials && f.SenderCredlID == model.ReceiverCredID && f.ReceiverCredID == model.ReceiverCredID && f.NotificationType == model.NotificationType && f.TargetID == model.TargetPostID && f.TokenDevicesID == model.TokenDevicesID)) { tblUserNotifications objdeviceNft = new tblUserNotifications { SenderCredlID = userCredetials, ReceiverCredID = model.ReceiverCredID, NotificationType = model.NotificationType, SenderUserName = model.SenderUserName, Status = true, IsRead = false, TargetID = model.TargetPostID, CreatedDate = model.CreatedNotificationUtcDateTime, TokenDevicesID = model.TokenDevicesID, ChallengeToFriendId = model.ChallengeToFriendId, IsFriendChallenge = model.IsFriendChallenge, IsOnBoarding = model.IsOnBoarding }; _dbContext.UserNotifications.Add(objdeviceNft); _dbContext.SaveChanges(); return(objdeviceNft.NotificationID); } return(0); } finally { traceLog.AppendLine("End: GetSaveDevicesNotification --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get User Total Friend PendingChallenges list to user /// </summary> /// <param name="credID"></param> /// <returns></returns> public static List <PendingChallengeVM> GetTotalPendingChallengeToUser(int credID) { using (LinksMediaContext dataContext = new LinksMediaContext()) { StringBuilder traceLog = null; // string userlastDevicesID = string.Empty; List <PendingChallengeVM> listPendingChallenge = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetTotalPendingChallengeToUser()"); if (credID > 0) { listPendingChallenge = (from c in dataContext.Challenge join ctf in dataContext.ChallengeToFriends on c.ChallengeId equals ctf.ChallengeId join ct in dataContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId join crd in dataContext.Credentials on ctf.SubjectId equals crd.Id where crd.UserType == Message.UserTypeUser && c.IsActive && ctf.TargetId == credID && ctf.IsActive && ctf.IsPending == true && ctf.IsActive orderby ctf.ChallengeDate descending select new PendingChallengeVM { ChallengeId = c.ChallengeId, ChallengeName = c.ChallengeName, ChallengeByUserName = ctf.ChallengeByUserName }).ToList(); listPendingChallenge = new List <PendingChallengeVM>(); listPendingChallenge = listPendingChallenge.GroupBy(pl => pl.ChallengeId) .Select(grp => grp.FirstOrDefault()) .ToList(); } return(listPendingChallenge); } catch { throw; } finally { traceLog.AppendLine("End: GetTotalPendingChallengeToUser() --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } } }
/// <summary> /// Get ExecisesList based serach cateria value /// </summary> /// <param name="search"></param> /// <returns></returns> public static List <ViewExerciseVM> GetExecisesList(string search = null) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: GetExecisesList---- " + DateTime.Now.ToLongDateString()); List <ViewExerciseVM> exerlistlist = dataContext.Exercise.Where(ex => ex.IsActive) .Select(exe => new ViewExerciseVM { ExerciseId = exe.ExerciseId, ExerciseName = exe.ExerciseName, Index = exe.Index, ThumnailUrl = exe.ThumnailUrl, ExerciseVideoUrl = exe.V720pUrl, TeamId = exe.TeamID, TrainerId = exe.TrainerID, SelectedStatus = exe.ExerciseStatus }).OrderBy(ch => ch.ExerciseName).ToList(); if (!string.IsNullOrEmpty(search)) { search = search.ToLower(CultureInfo.InvariantCulture); exerlistlist = exerlistlist.Where(ch => (ch.ExerciseName != null && ch.ExerciseName.ToLower(CultureInfo.InvariantCulture).IndexOf(search, 0, StringComparison.OrdinalIgnoreCase) > -1)) .OrderBy(ch => ch.ExerciseName).ToList <ViewExerciseVM>(); } return(exerlistlist); } catch { throw; } finally { traceLog.AppendLine("End GetExecisesList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Save Failed to Sprout Server /// </summary> /// <param name="FailedExecise"></param> public static void SaveFailedSproutServer(List <UpdateExerciseSproutLink> FailedExecise) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: SaveFailedSproutServer---- " + DateTime.Now.ToLongDateString()); if (FailedExecise != null && FailedExecise.Count > 0) { string UploadGuid = Guid.NewGuid().ToString(); DateTime createdDatetime = DateTime.Now; List <tblExerciseUploadHistory> failedHistoryList = new List <tblExerciseUploadHistory>(); FailedExecise.ForEach(failexe => { tblExerciseUploadHistory tblExerciseUploadHistory = new tblExerciseUploadHistory { Index = failexe.Index, ExerciseName = failexe.ExerciseName, FailedVideoName = failexe.FailedVideoName, TeamId = failexe.TeamID, TrainerId = failexe.TrainerID, UploadHistoryGuidId = UploadGuid, CreatedDate = createdDatetime }; failedHistoryList.Add(tblExerciseUploadHistory); }); dataContext.ExerciseUploadHistory.AddRange(failedHistoryList); dataContext.SaveChanges(); } } catch { return; } finally { traceLog.AppendLine("End SaveFailedSproutServer : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to get featured activity fron the database /// </summary> /// <returns>IEnumerable<FeaturedActivityQueue></returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/16/2015 /// </devdoc> public static IEnumerable <FeaturedActivityQueue> GetFeaturedActivity() { StringBuilder traceLog = null; using (LinksMediaContext dataContext = new LinksMediaContext()) { traceLog = new StringBuilder(); try { traceLog.AppendLine("Start: GetFeaturedActivity"); DateTime todayDate = DateTime.Now.Date; // IEnumerable<FeaturedActivityQueue> objActivity return((from A in dataContext.Activity join C in dataContext.Credentials on A.TrainerId equals C.Id join S in dataContext.States on A.State equals S.StateCode join Ct in dataContext.Cities on A.City equals Ct.CityId join T in dataContext.Trainer on C.UserId equals T.TrainerId join FA in dataContext.FeaturedActivityQueue on A.ActivityId equals FA.ActivityId where FA.StartDate <= todayDate && FA.EndDate >= todayDate orderby A.ModifiedDate descending select new FeaturedActivityQueue { QueueId = FA.Id, ActivityId = A.ActivityId, NameOfActivity = A.NameOfActivity, TrainerName = T.FirstName + " " + T.LastName, DateofEvent = A.DateOfEvent, Location = Ct.CityName + ", " + S.StateName, PromotionText = A.PromotionText }).ToList()); //return objActivity; } catch { throw; } finally { traceLog.AppendLine("GetFeaturedActivity end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to change password /// </summary> /// <param></param> /// <returns>bool</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 07/24/2015 /// </devdoc> public static bool ChangePassword(EditPasswordVM model) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { EncryptDecrypt objEncrypt = null; Credentials cred = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChangePassword"); bool flag = false; cred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (cred != null) { if (IsOldPasswordCorrect(model.OldPassword, cred.Id)) { objEncrypt = new EncryptDecrypt(); tblCredentials objCredential = _dbContext.Credentials.Where(crd => crd.Id == cred.Id).FirstOrDefault(); model.NewPassword = objEncrypt.EncryptString(model.NewPassword); if (objCredential != null) { objCredential.Password = model.NewPassword; } _dbContext.SaveChanges(); flag = true; } } return(flag); } finally { if (objEncrypt != null) { objEncrypt.Dispose(); objEncrypt = null; } traceLog.AppendLine("End: ChangePassword --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Function to get challenge details of sponsor challenge /// </summary> /// <returns>IEnumerable<SponsorChallengeQueue></returns> /// <devdoc> /// Developer Name - Raghuraj Singh /// Date - 04/20/2015 /// </devdoc> public static List <SponsorChallengeQueue> GetAllSponsorChallenge() { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetAllSponsorChallenge---- " + DateTime.Now.ToLongDateString()); DateTime todayDate = DateTime.Now.Date; var objSponsorChallengeQueueList = (from tc in _dbContext.TrainerChallenge join chlnge in _dbContext.Challenge on tc.ChallengeId equals chlnge.ChallengeId join t in _dbContext.Trainer on tc.TrainerId equals t.TrainerId join c in _dbContext.Credentials on tc.TrainerId equals c.UserId join uc in _dbContext.UserChallenge on tc.ResultId equals uc.Id where c.UserType == Message.UserTypeTrainer && tc.StartDate <= todayDate && tc.EndDate >= todayDate && chlnge.IsActive == true select new SponsorChallengeQueue { QueueId = tc.QueueId, ChallengeName = chlnge.ChallengeName, TrainerName = t.FirstName + " " + t.LastName, SponsorName = tc.SponsorName, StrengthCount = _dbContext.UserChallenge.Where(s => s.ChallengeId == chlnge.ChallengeId).Select(y => y.UserId).Distinct().Count(), AcceptedDate = tc.EndDate }).ToList(); return(objSponsorChallengeQueueList); } catch { throw; } finally { traceLog.AppendLine("End GetAllSponsorChallenge : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
public static bool UpdatePassword(ChangePassword model) { bool success = false; StringBuilder traceLog = new StringBuilder(); EncryptDecrypt objEncrypt = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { objEncrypt = new EncryptDecrypt(); traceLog.AppendLine("Start: Login, ValidateUser Method with Param UserName: "******"CredentialId"]); string password = objEncrypt.EncryptString(AntiXssEncoder.HtmlEncode(model.OldPassword.Trim(), false)); string newpassword = objEncrypt.EncryptString(AntiXssEncoder.HtmlEncode(model.NewPassword.Trim(), false)); tblCredentials credential = _dbContext.Credentials.FirstOrDefault(m => m.Id == credentialId && m.Password == password); if (credential == null) { return(success); } else { credential.Password = newpassword; _dbContext.Entry(credential).State = EntityState.Modified; _dbContext.SaveChanges(); success = true; } } catch { throw; } finally { objEncrypt.Dispose(); traceLog.AppendLine("Index Start end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } return(success); }
/// <summary> /// Select UserPersonalTrainer /// </summary> /// <param name="usertrainerdetails"></param> /// <returns></returns> public static bool SelectUserPersonalTrainer(UserPersonalTrainerVM usertrainerdetails) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: SelectUserPersonalTrainer---- " + DateTime.Now.ToLongDateString()); if (usertrainerdetails.TrainerCredID > 0) { Credentials cred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (cred.UserType.Equals(Message.UserTypeUser, StringComparison.OrdinalIgnoreCase)) { tblUser user = dataContext.User.FirstOrDefault(usr => usr.UserId == cred.UserId); if (user != null) { user.PersonalTrainerCredId = usertrainerdetails.TrainerCredID; dataContext.SaveChanges(); if (usertrainerdetails.TrainerCredID > 0) { string selectedUserName = string.Empty; selectedUserName = user.FirstName + " " + user.LastName; NotificationApiBL.SendSelectPrimaryTrainerNotificationToTrainer(usertrainerdetails.TrainerCredID, selectedUserName, cred.UserId, cred.UserType); } return(true); } } } return(false); } catch { throw; } finally { traceLog.AppendLine("End GetTrainerLibraryChallengeList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get TrainerLibrary Menu List with Name and challenge Type Id /// </summary> /// <returns></returns> public static List <TrainerLibraryMenuVM> GetTrainerLibraryMenuList() { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { List <TrainerLibraryMenuVM> objTrainerLibraryMenulist = null; try { traceLog.AppendLine("Start: GetTrainerLibraryMenuList()---- " + DateTime.Now.ToLongDateString()); objTrainerLibraryMenulist = new List <TrainerLibraryMenuVM> { new TrainerLibraryMenuVM() { MenuItemId = 1, MenuName = ConstantHelper.constFitnessTestName }, new TrainerLibraryMenuVM() { MenuItemId = ConstantHelper.constWorkoutChallengeSubType, MenuName = ConstantHelper.constWorkoutChallenge }, new TrainerLibraryMenuVM() { MenuItemId = ConstantHelper.constProgramChallengeSubType, MenuName = ConstantHelper.constProgramChallenge }, new TrainerLibraryMenuVM() { MenuItemId = ConstantHelper.constWellnessChallengeSubType, MenuName = ConstantHelper.constWellnessName }, }; return(objTrainerLibraryMenulist); } catch { throw; } finally { traceLog.AppendLine("End GetTrainerLibraryMenuList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }