Ejemplo n.º 1
0
        /// <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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete the Program based on program Id
        /// </summary>
        /// <param name="Id"></param>
        public static void DeleteProgram(int Id)
        {
            StringBuilder traceLog = new StringBuilder();

            using (LinksMediaContext dataContext = new LinksMediaContext())
            {
                using (System.Data.Entity.DbContextTransaction dbTran = dataContext.Database.BeginTransaction())
                {
                    try
                    {
                        traceLog.AppendLine("Start: DeleteProgram for deleting challenge");
                        /*Delete challenge and exercise association*/
                        List <tblPWAssociation> objPWAssociationList = dataContext.PWAssociation.Where(ce => ce.ProgramChallengeId == Id).ToList();
                        dataContext.PWAssociation.RemoveRange(objPWAssociationList);
                        List <tblPWWorkoutsAssociation> objPWWorkoutsAssociationList = (from pw in dataContext.PWAssociation
                                                                                        join pww in dataContext.PWWorkoutsAssociation
                                                                                        on pw.PWRocordId equals pww.PWRocordId
                                                                                        where pw.ProgramChallengeId == Id
                                                                                        select pww
                                                                                        ).ToList();
                        if (objPWWorkoutsAssociationList != null && objPWWorkoutsAssociationList.Count > 0)
                        {
                            dataContext.PWWorkoutsAssociation.RemoveRange(objPWWorkoutsAssociationList);
                        }
                        // Get
                        List <tblUserAcceptedProgramWorkouts> objUserAcceptedProgramWorkoutsList = (from apgm in dataContext.UserAcceptedProgramWeeks
                                                                                                    join pww in dataContext.UserAcceptedProgramWorkouts
                                                                                                    on apgm.UserAcceptedProgramWeekId equals pww.UserAcceptedProgramWeekId
                                                                                                    where pww.ProgramChallengeId == Id
                                                                                                    select pww
                                                                                                    ).ToList();
                        List <tblUserAcceptedProgramWeek> objUserAcceptedProgramWeeknList = (from apgm in dataContext.UserActivePrograms
                                                                                             join pww in dataContext.UserAcceptedProgramWeeks
                                                                                             on apgm.UserAcceptedProgramId equals pww.UserAcceptedProgramId
                                                                                             where apgm.ProgramId == Id
                                                                                             select pww
                                                                                             ).ToList();
                        List <tblUserActivePrograms> objUserActiveProgramslist = dataContext.UserActivePrograms.Where(ce => ce.ProgramId == Id).ToList();

                        // Delete  the User AcceptedProgramW orkoutsList
                        if (objUserAcceptedProgramWorkoutsList != null)
                        {
                            dataContext.UserAcceptedProgramWorkouts.RemoveRange(objUserAcceptedProgramWorkoutsList);
                        }
                        // Delete  the User AcceptedProgramW orkoutsList
                        if (objUserAcceptedProgramWeeknList != null)
                        {
                            dataContext.UserAcceptedProgramWeeks.RemoveRange(objUserAcceptedProgramWeeknList);
                        }
                        // Delete  the User User Accepted Program Weekn List
                        if (objUserAcceptedProgramWeeknList != null)
                        {
                            dataContext.UserActivePrograms.RemoveRange(objUserActiveProgramslist);
                        }

                        /*Delete userChallenge Challenge*/
                        List <tblUserChallenges> objUserChallenges = dataContext.UserChallenge.Where(ce => ce.ChallengeId == Id).ToList();
                        dataContext.UserChallenge.RemoveRange(objUserChallenges);

                        /*delete challenege*/
                        tblChallenge challenge = dataContext.Challenge.Find(Id);
                        dataContext.Challenge.Remove(challenge);

                        dataContext.SaveChanges();
                        dbTran.Commit();
                    }
                    catch
                    {
                        dbTran.Rollback();
                        throw;
                    }
                    finally
                    {
                        traceLog.AppendLine("DeleteProgram  end() : --- " + DateTime.Now.ToLongDateString());
                        LogManager.LogManagerInstance.WriteTraceLog(traceLog);
                    }
                }
            }
        }