/// <summary> /// Function to get challenge details of sponsor challenge /// </summary> /// <returns>SponsorChallengeDetailVM</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 03/31/2015 /// </devdoc> public static SponsorChallengeDetailVM GetSponsorChallengeDetails(int challengeId) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: GetSponsorChallengeDetails---- " + DateTime.Now.ToLongDateString()); SponsorChallengeDetailVM objChallengedetail = (from c in _dbContext.Challenge join cred in _dbContext.Credentials on c.CreatedBy equals cred.Id join ct in _dbContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId join tc in _dbContext.TrainerChallenge on c.ChallengeId equals tc.ChallengeId join uc in _dbContext.UserChallenge on tc.ResultId equals uc.Id join h in _dbContext.HypeVideos on tc.HypeVideoId equals h.RecordId where c.ChallengeId == challengeId && c.IsActive == true select new SponsorChallengeDetailVM { ChallengeId = c.ChallengeId, ChallengeName = c.ChallengeName, DifficultyLevel = c.DifficultyLevel, ChallengeType = ct.ChallengeType, Strenght = _dbContext.UserChallenge.Where(uchlng => uchlng.ChallengeId == c.ChallengeId).Select(y => y.UserId).Distinct().Count(), ResultUnit = ct.ResultUnit, ResultUnitSuffix = uc.ResultUnit, ChallengeDescription = ct.ChallengeSubType, Excercises = (from exer in _dbContext.Exercise join ce in _dbContext.CEAssociation on exer.ExerciseId equals ce.ExerciseId where ce.ChallengeId == c.ChallengeId select new ExerciseVM { ExerciseId = exer.ExerciseId, ExerciseName = exer.ExerciseName, ExcersiceDescription = exer.Description, ChallengeExcerciseDescription = ce.Description, VedioLink = exer.VideoLink, Index = exer.Index, Reps = ce.Reps, WeightForManDB = ce.WeightForMan, WeightForWomanDB = ce.WeightForWoman, }).ToList(), HypeVideo = h.HypeVideo, Result = (uc.Result == null ? "" : uc.Result) + " " + (uc.Fraction == null ? "" : uc.Fraction), VariableValue = c.VariableValue, ChallengeSubTypeId = ct.ChallengeSubTypeId, VariableUnit = ct.Unit, CreatedByUserType = cred.UserType, CreatedByTrainerId = cred.UserId, PersonalBestUserId = uc.UserId }).FirstOrDefault(); if (objChallengedetail != null) { if (objChallengedetail.ResultUnit.Equals("Time")) { objChallengedetail.Result = CommonApiBL.GetChallengeResultBasedOnResultUnit(objChallengedetail.Result); } if (!string.IsNullOrEmpty(objChallengedetail.Result)) { objChallengedetail.Result = objChallengedetail.Result.Trim(); } if (!string.IsNullOrEmpty(objChallengedetail.ChallengeType)) { objChallengedetail.ChallengeType = objChallengedetail.ChallengeType.Split(' ')[0]; } if (objChallengedetail.CreatedByUserType.Equals(Message.UserTypeTrainer, StringComparison.OrdinalIgnoreCase)) { var objTrainer = _dbContext.Trainer.FirstOrDefault(t => t.TrainerId == objChallengedetail.CreatedByTrainerId); if (objTrainer != null) { objChallengedetail.CreatedByTrainerName = objTrainer.FirstName + " " + objTrainer.LastName; objChallengedetail.CreatedByProfilePic = string.IsNullOrEmpty(objTrainer.TrainerImageUrl) ? string.Empty : CommonUtility.VirtualPath + Message.ProfilePicDirectory + objTrainer.TrainerImageUrl; } } else { objChallengedetail.CreatedByTrainerId = 0; } } objChallengedetail.Excercises.ForEach( exer => { exer.WeightForMan = exer.WeightForManDB > 0 ? exer.WeightForManDB.ToString() + " " + ConstantHelper.constlbs : null; exer.WeightForWoman = exer.WeightForWomanDB > 0 ? exer.WeightForWomanDB.ToString() + " " + ConstantHelper.constlbs : null; exer.VedioLink = CommonUtility.VirtualFitComExercisePath + Message.ExerciseVideoDirectory + exer.VedioLink; exer.ExerciseThumnail = CommonWebApiBL.GetSaveExerciseThumbnail(exer.VedioLink, exer.ExerciseName); }); string tempdesc = string.Empty; if (objChallengedetail != null && !string.IsNullOrEmpty(objChallengedetail.VariableValue)) { tempdesc = CommonApiBL.GetChallengeVariableValueBasedVariableUnit(objChallengedetail.VariableValue, objChallengedetail.VariableUnit); } ////End the modification if (!string.IsNullOrEmpty(tempdesc)) { tempdesc = tempdesc.Trim(); } objChallengedetail.ChallengeDescription = objChallengedetail.ChallengeDescription.Replace("____", tempdesc) .Replace(ConstantHelper.constAmoutOfTime, ConstantHelper.constQustionMark). Replace(ConstantHelper.constAmoutOfTimeSecond, ConstantHelper.constQustionMark); if (objChallengedetail != null && !string.IsNullOrEmpty(objChallengedetail.VariableValue)) { objChallengedetail.VariableValue = CommonApiBL.GetChallengeVariableValueBasedOnTime(objChallengedetail.VariableValue); } tblCredentials objCredentials = _dbContext.Credentials.FirstOrDefault(c => c.Id == objChallengedetail.PersonalBestUserId); if (objCredentials != null) { objChallengedetail.PersonalBestUserName = CommonReportingUtility.GetUserFullNameBasedUserCredIdAndUserType(_dbContext, objCredentials.Id, objCredentials.UserType); } return(objChallengedetail); } catch { throw; } finally { traceLog.AppendLine("End GetSponsorChallengeDetails : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }
/// <summary> /// Copy of Program By exitsing program Id /// </summary> /// <param name="programId"></param> /// <param name="userType"></param> /// <param name="credentialId"></param> /// <returns></returns> public static int CreateCopyProgramById(int programId, string userType, int credentialId) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { using (System.Data.Entity.DbContextTransaction dbTran = dataContext.Database.BeginTransaction()) { try { /*Get challenge detail by GetCopyProgrameById*/ traceLog.AppendLine("Start: GetCopyProgrameById for retrieving challenge by programId:" + programId + ",userType-" + userType); tblChallenge copyProgram = null; int newProgramId = 0; tblChallenge programdDetails = dataContext.Challenge.Find(programId); if (programdDetails != null) { copyProgram = new tblChallenge { TrainerId = programdDetails.TrainerId, IsActive = programdDetails.IsActive, IsDraft = programdDetails.IsDraft, Description = programdDetails.Description, DifficultyLevel = programdDetails.DifficultyLevel, FFChallengeDuration = programdDetails.FFChallengeDuration, GlobalResultFilterValue = programdDetails.GlobalResultFilterValue, IsPremium = programdDetails.IsPremium, ProgramImageUrl = programdDetails.ProgramImageUrl, VariableValue = programdDetails.VariableValue, ChallengeName = programdDetails.ChallengeName + ConstantHelper.constChallengeCopyAppenedName, ChallengeSubTypeId = programdDetails.ChallengeSubTypeId, ChallengeDetail = programdDetails.ChallengeDetail, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, CreatedBy = credentialId, ModifiedBy = credentialId, IsSubscription = programdDetails.IsSubscription, IsFeatured = programdDetails.IsFeatured, FeaturedImageUrl = programdDetails.FeaturedImageUrl, }; dataContext.Challenge.Add(copyProgram); dataContext.SaveChanges(); newProgramId = copyProgram.ChallengeId; /*Get exercise detail for the respective challenge*/ List <tblPWAssociation> objPWAssociationnList = dataContext.PWAssociation.Where(ce => ce.ProgramChallengeId == programId).ToList(); objPWAssociationnList.ForEach(pw => { tblPWAssociation objProgramWeekWorkout = new tblPWAssociation(); objProgramWeekWorkout.ProgramChallengeId = newProgramId; objProgramWeekWorkout.AssignedDifficulyLevelId = pw.AssignedDifficulyLevelId; objProgramWeekWorkout.AssignedTrainerId = pw.AssignedTrainerId; objProgramWeekWorkout.AssignedTrainingzone = pw.AssignedTrainingzone; objProgramWeekWorkout.CreatedBy = credentialId; objProgramWeekWorkout.CreatedDate = DateTime.Now; objProgramWeekWorkout.ModifiedBy = credentialId; objProgramWeekWorkout.ModifiedDate = DateTime.Now; dataContext.PWAssociation.Add(objProgramWeekWorkout); dataContext.SaveChanges(); long newPWRocordId = objProgramWeekWorkout.PWRocordId; List <tblPWWorkoutsAssociation> prmWAssociationList = dataContext.PWWorkoutsAssociation.Where(pww => pww.PWRocordId == pw.PWRocordId).ToList(); List <tblPWWorkoutsAssociation> weekWorkouList = new List <tblPWWorkoutsAssociation>(); prmWAssociationList.ForEach(pww => { var objPgrmWorkout = new tblPWWorkoutsAssociation(); objPgrmWorkout.WorkoutChallengeId = pww.WorkoutChallengeId; objPgrmWorkout.PWRocordId = newPWRocordId; objPgrmWorkout.CreatedBy = credentialId; objPgrmWorkout.CreatedDate = DateTime.Now; objPgrmWorkout.ModifiedBy = credentialId; objPgrmWorkout.ModifiedDate = DateTime.Now; weekWorkouList.Add(objPgrmWorkout); }); dataContext.PWWorkoutsAssociation.AddRange(weekWorkouList); dataContext.SaveChanges(); }); if (newProgramId > 0) { List <DDTeams> selecetdTeams = CommonReportingUtility.GetSelectedTeamByChallengeId(dataContext, programId, true); if (selecetdTeams != null && selecetdTeams.Count > 0) { List <tblNoTrainerChallengeTeam> objtblNoTrainerChallengeTeam = new List <tblNoTrainerChallengeTeam>(); selecetdTeams.ForEach(notrainer => { objtblNoTrainerChallengeTeam.Add(new tblNoTrainerChallengeTeam() { TeamId = notrainer.TeamId, IsProgram = true, ChallengeId = newProgramId, IsFittnessTest = false }); }); dataContext.NoTrainerChallengeTeams.AddRange(objtblNoTrainerChallengeTeam); } List <TrendingCategory> selecetdTrendingCategory = CommonReportingUtility.GetChallengeTrendingAssociationsList(dataContext, programId, ConstantHelper.constProgramChallengeSubType, true); if (selecetdTrendingCategory != null && selecetdTrendingCategory.Count > 0) { List <tblChallengeTrendingAssociation> lstChallengeTrendingAssociation = new List <tblChallengeTrendingAssociation>(); selecetdTrendingCategory.ForEach(trendCat => { lstChallengeTrendingAssociation.Add(new tblChallengeTrendingAssociation() { TrendingCategoryId = trendCat.TrendingCategoryId, IsProgram = true, ChallengeId = newProgramId }); }); dataContext.ChallengeTrendingAssociations.AddRange(lstChallengeTrendingAssociation); } List <ChallengeCategory> selecetdChallengeCategory = CommonReportingUtility.GetSelectedChallengeCategoryAssociations(dataContext, programId, true); if (selecetdChallengeCategory != null && selecetdChallengeCategory.Count > 0) { List <tblChallengeCategoryAssociation> listChallengeCategoryAssociation = new List <tblChallengeCategoryAssociation>(); selecetdChallengeCategory.ForEach(progCat => { listChallengeCategoryAssociation.Add(new tblChallengeCategoryAssociation() { ChallengeCategoryId = progCat.ChallengeCategoryId, IsProgram = true, ChallengeId = newProgramId }); }); dataContext.ChallengeCategoryAssociations.AddRange(listChallengeCategoryAssociation); } dataContext.SaveChanges(); } } dbTran.Commit(); return(newProgramId); } catch { dbTran.Rollback(); throw; } finally { traceLog.AppendLine("GetChallangeById end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } } }