public async Task AddProgramWorkout(CreateOrUpdateProgramWorkoutRequest request) { if (request.Period <= 0) { throw new ArgumentException(); } var pw = new ProgramWorkout { Name = request.Name, AuthorId = request.AuthorId, Period = request.Period }; await context.ProgramWorkouts.AddAsync(pw); await context.SaveChangesAsync(); }
/// <summary> /// Get Program details By Program Id /// </summary> /// <param name="id"></param> /// <returns></returns> public static ViewProgramDetail GetProgramById(int id) { StringBuilder traceLog = new StringBuilder(); using (LinksMediaContext dataContext = new LinksMediaContext()) { try { /*Get challenge detail by challenge*/ traceLog.AppendLine("Start: GetProgramWorkoutById() for retrieving challenge by challengeid:" + id); ViewProgramDetail challenge = (from c in dataContext.Challenge join ct in dataContext.ChallengeType on c.ChallengeSubTypeId equals ct.ChallengeSubTypeId where c.ChallengeId == id select new ViewProgramDetail { ChallengeId = c.ChallengeId, ChallengeName = c.ChallengeName, IsFeatured = c.IsFeatured, FeaturedImageUrl = c.FeaturedImageUrl, ProgramImageUrl = c.ProgramImageUrl, ChallengeType = ct.ChallengeSubTypeId, ChallengeType_Name = ct.ChallengeSubType, ChallengeSubType_Description = c.Description, ChallengeCategoryNameList = (from chgCat in dataContext.ChallengeCategoryAssociations join cc in dataContext.ChallengeCategory on chgCat.ChallengeCategoryRecordId equals cc.ChallengeCategoryId where chgCat.ChallengeId == c.ChallengeId && chgCat.IsProgram == (ConstantHelper.constProgramChallengeSubType == c.ChallengeSubTypeId) select cc.ChallengeCategoryName ).Distinct().ToList <string>(), DifficultyLevel = c.DifficultyLevel }).FirstOrDefault(); if (challenge != null) { /*Get exercise detail for the respective challenge*/ List <tblPWAssociation> objPWAssociationnList = dataContext.PWAssociation.Where(ce => ce.ProgramChallengeId == id).ToList(); List <ProgramWeekWorkout> programWeekWorkouList = new List <ProgramWeekWorkout>(); objPWAssociationnList.ForEach(pw => { ProgramWeekWorkout objProgramWeekWorkout = new ProgramWeekWorkout(); List <tblPWWorkoutsAssociation> prmWAssociationList = dataContext.PWWorkoutsAssociation.Where(pww => pww.PWRocordId == pw.PWRocordId).ToList(); List <ProgramWorkout> weekWorkouList = new List <ProgramWorkout>(); prmWAssociationList.ForEach(pww => { ProgramWorkout objPgrmWorkout = new ProgramWorkout(); objPgrmWorkout.WorkoutId = pww.WorkoutChallengeId; objPgrmWorkout.WorkoutName = dataContext.Challenge.Where(c => c.ChallengeId == pww.WorkoutChallengeId).Select(ch => ch.ChallengeName).FirstOrDefault(); weekWorkouList.Add(objPgrmWorkout); }); objProgramWeekWorkout.WeekId = pw.PWRocordId; objProgramWeekWorkout.WeekWorkoutList = weekWorkouList; programWeekWorkouList.Add(objProgramWeekWorkout); }); challenge.SetProgramWeekWorkoutList(programWeekWorkouList); } return(challenge); } catch { throw; } finally { traceLog.AppendLine("GetProgramWorkoutById end() : --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }