/// <summary> /// Get TrainerLibrary ChallengeList /// </summary> /// <param name="model"></param> /// <param name="isTeamJoined"></param> /// <returns></returns> /// <devdoc> /// Developer Name - Irshad Ansari /// Date - 04/26/2016 /// </devdoc> public static ChallengeTabVM GetTrainerLibraryChallengeList(int userId, string userType, int startIndex, int endIndex) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: GetTrainerLibraryChallengeList---- " + 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) { List <MainChallengeVM> listMainVM = (from c in dataContext.Challenge join ct in dataContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId where c.IsActive && c.TrainerId == trainerCredId orderby c.ChallengeName ascending select new MainChallengeVM { ChallengeId = c.ChallengeId, ChallengeName = c.ChallengeName, DifficultyLevel = c.DifficultyLevel, ChallengeType = ct.ChallengeType, Description = c.Description, IsSubscription = c.IsSubscription, TempEquipments = (from trzone in dataContext.ChallengeEquipmentAssociations join bp in dataContext.Equipments on trzone.EquipmentId equals bp.EquipmentId where trzone.ChallengeId == c.ChallengeId select bp.Equipment).Distinct().ToList <string>(), TempTargetZone = (from trzone in dataContext.TrainingZoneCAssociations join bp in dataContext.BodyPart on trzone.PartId equals bp.PartId where trzone.ChallengeId == c.ChallengeId select bp.PartName).Distinct().ToList <string>(), Strenght = dataContext.UserChallenge.Where(uc => uc.ChallengeId == c.ChallengeId).Select(y => y.UserId).Distinct().Count(), ResultUnit = ct.ResultUnit, IsWellness = (ct.ChallengeSubTypeId == ConstantHelper.constWellnessChallengeSubType) ? true : false, }).ToList(); if (listMainVM != null && listMainVM.Count > 0) { listMainVM.ForEach(r => { r.ChallengeType = r.ChallengeType.Split(' ')[0]; if (r.TempTargetZone != null && r.TempTargetZone.Count > 0) { r.TargetZone = string.Join(", ", r.TempTargetZone); } r.TempTargetZone = null; if (r.TempEquipments != null && r.TempEquipments.Count > 0) { r.Equipment = string.Join(", ", r.TempEquipments); } r.TempEquipments = null; }); int totalcount = listMainVM.Count; listMainVM = (from l in listMainVM select l).Skip(startIndex).Take(endIndex - startIndex).ToList(); if ((totalcount) > endIndex) { objChallengeTabVM.IsMoreAvailable = true; } //Challenge feed sorted by acceptors if (listMainVM != null) { listMainVM = listMainVM.OrderBy(chlng => chlng.ChallengeName).ToList(); } objChallengeTabVM.ChallengeList = listMainVM; } } return(objChallengeTabVM); } catch { throw; } finally { traceLog.AppendLine("End GetTrainerLibraryChallengeList : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Get FreeForm TrainerLibrary Challenges By SubCategory /// </summary> /// <param name="model"></param> /// <returns></returns> public static ChallengeTabVM GetFreeFormTrainerLibraryChallengesBySubCategory(TrainerLibraryWorkoutListByCategory model) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { traceLog.AppendLine("Start: GetFreeFormTrainerLibraryChallengesBySubCategory---- " + DateTime.Now.ToLongDateString()); int trainerCredId = -1; ChallengeTabVM objChallengeTabVM = new ChallengeTabVM(); Credentials objCred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); int usercredId = objCred.Id; if (!string.IsNullOrEmpty(model.UserType) && model.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 == model.UserId select crd.Id).FirstOrDefault(); } if (trainerCredId > 0) { List <MainChallengeVM> listMainVM = (from c in dataContext.Challenge join ct in dataContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId where c.IsActive && c.TrainerId == trainerCredId && ct.ChallengeSubTypeId == model.WorkoutCategoryID // && c.IsPremium == true orderby c.CreatedDate descending select new MainChallengeVM { ChallengeId = c.ChallengeId, ChallengeName = c.ChallengeName, DifficultyLevel = c.DifficultyLevel, ChallengeType = ct.ChallengeType, Description = c.Description, IsSubscription = c.IsSubscription, TempEquipments = (from trzone in dataContext.ChallengeEquipmentAssociations join bp in dataContext.Equipments on trzone.EquipmentId equals bp.EquipmentId where trzone.ChallengeId == c.ChallengeId select bp.Equipment).Distinct().ToList <string>(), TempTargetZone = (from trzone in dataContext.TrainingZoneCAssociations join bp in dataContext.BodyPart on trzone.PartId equals bp.PartId where trzone.ChallengeId == c.ChallengeId select bp.PartName).Distinct().ToList <string>(), IsActive = dataContext.UserActivePrograms.Where(uc => uc.ProgramId == c.ChallengeId && uc.IsCompleted == false && uc.UserCredId == usercredId).Select(y => y.ProgramId).Distinct().Count() > 0, Strenght = dataContext.UserChallenge.Where(uc => uc.ChallengeId == c.ChallengeId).Select(y => y.UserId).Distinct().Count(), ResultUnit = ct.ResultUnit, IsWellness = (ct.ChallengeSubTypeId == ConstantHelper.constWellnessChallengeSubType) ? true : false, ProgramImageUrl = c.ProgramImageUrl, ChallengeCategoryList = dataContext.ChallengeCategoryAssociations. Where(cc => cc.ChallengeId == c.ChallengeId && cc.IsProgram == (ConstantHelper.constProgramChallengeSubType == c.ChallengeSubTypeId)).Select(ch => ch.ChallengeCategoryId).ToList() }).ToList(); if (listMainVM != null && listMainVM.Count > 0) { listMainVM = listMainVM.Where(ch => ch.ChallengeCategoryList != null && ch.ChallengeCategoryList.Contains(model.WorkoutSubCategoryID)).ToList(); listMainVM.ForEach(r => { string filePath = HttpContext.Current.Server.MapPath("~") + "\\images\\profilepic\\" + r.ProgramImageUrl; if (System.IO.File.Exists(filePath)) { using (Bitmap objBitmap = new Bitmap(filePath)) { double sourceWidth = Convert.ToDouble(objBitmap.Size.Width, CultureInfo.CurrentCulture); double sourceHeight = Convert.ToDouble(objBitmap.Size.Height, CultureInfo.CurrentCulture); r.Height = (sourceWidth > 0) ? Convert.ToString(sourceHeight, CultureInfo.CurrentCulture) : string.Empty; r.Width = (sourceWidth > 0) ? Convert.ToString(sourceWidth, CultureInfo.CurrentCulture) : string.Empty; } } else { r.Height = string.Empty; r.Width = string.Empty; } r.ChallengeType = r.ChallengeType.Split(' ')[0]; r.ProgramImageUrl = (string.IsNullOrEmpty(r.ProgramImageUrl)) ? string.Empty : File.Exists(HttpContext.Current.Server.MapPath("~/" + Message.ProfilePicDirectory + r.ProgramImageUrl)) ? CommonUtility.VirtualPath + Message.ProfilePicDirectory + r.ProgramImageUrl : string.Empty; if (r.TempTargetZone != null && r.TempTargetZone.Count > 0) { r.TargetZone = string.Join(", ", r.TempTargetZone); } r.TempTargetZone = null; if (r.TempEquipments != null && r.TempEquipments.Count > 0) { r.Equipment = string.Join(", ", r.TempEquipments); } r.TempEquipments = null; }); int totalcount = listMainVM.Count(); listMainVM = (from l in listMainVM select l).Skip(model.StartIndex).Take(model.EndIndex - model.StartIndex).ToList(); if ((totalcount) > model.StartIndex) { objChallengeTabVM.IsMoreAvailable = true; } //Challenge feed sorted by acceptors if (listMainVM != null) { listMainVM = listMainVM.OrderByDescending(chlng => chlng.Strenght).ToList(); } objChallengeTabVM.ChallengeList = new List <MainChallengeVM>(); objChallengeTabVM.ChallengeList = listMainVM; } } return(objChallengeTabVM); } catch { throw; } finally { traceLog.AppendLine("End GetFreeFormTrainerLibraryChallengesBySubCategory : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }