Ejemplo n.º 1
0
        /// <summary>
        /// 添加新的训练计划,需要先删除旧的训练计划
        /// </summary>
        /// <param name="trainingPlan"></param>
        /// <returns></returns>
        public void SaveNewTrainingPlan(TrainingPlanEntity trainingPlan)
        {
            //使整个代码块成为事务性代码
            using (TransactionScope ts = new TransactionScope())
            {
                UploadManagementDAO uploadManagementDao = new UploadManagementDAO();
                //会员卡号ID
                string memberId = CommUtil.GetSettingString("memberId");
                //1.删除旧的训练计划
                trainingPlanDAO.DeletePlanByMemberId(memberId);
                //2.完成旧的训练课程
                trainingCourseDAO.UpdateCompleteState(memberId, true);
                List <long> listId1 = new List <long>();
                listId1 = trainingCourseDAO.ListIdByMemeberId(memberId);
                foreach (var id in listId1)
                {
                    //数据上传
                    uploadManagementDao.Insert(new UploadManagement(id, "bdl_training_course", 1));
                }
                //3.完成旧的训练活动
                activityDAO.UpdateCompleteState(memberId, true);
                List <long> listId = new List <long>();
                //通过memberId获取主键id
                listId = activityDAO.ListIdByMemeberId(memberId);
                foreach (var id in listId)
                {
                    //数据上传
                    uploadManagementDao.Insert(new UploadManagement(id, "bdl_activity", 1));
                }
                //4.新增训练计划
                trainingPlan.Id = KeyGenerator.GetNextKeyValueLong("bdl_training_plan");

                //判断登陆用户,是教练自己锻炼。还是教练为用户进行设置。决定传哪个主键设置
                string currentMemberPK = CommUtil.GetSettingString("memberPrimarykey");
                string currentCoachId  = CommUtil.GetSettingString("coachId");
                if ((currentMemberPK == null || currentMemberPK == "") && (currentCoachId != null && currentCoachId != ""))
                {
                    //无用户登陆。教练单独登陆时
                    //  从app.config中取id,转成int赋值
                    trainingPlan.Fk_member_id = ParseIntegerUtil.ParseInt(currentCoachId);
                }
                else
                {
                    //只要用户登录,就是为用户进行设置
                    //  从app.config中取id,转成int赋值
                    trainingPlan.Fk_member_id = ParseIntegerUtil.ParseInt(currentMemberPK);
                }


                //  设置会员卡号
                trainingPlan.Member_id = CommUtil.GetSettingString("memberId");
                //  设置状态为未删除
                trainingPlan.Is_deleted = false;
                //  创建时间
                trainingPlan.Gmt_create = System.DateTime.Now;
                //  插入新训练计划
                trainingPlanDAO.Insert(trainingPlan);
                //插入至上传表
                uploadManagementDao.Insert(new UploadManagement(trainingPlan.Id, "bdl_training_plan", 0));
                //5.更新App.config中训练计划id
                CommUtil.UpdateSettingString("trainingPlanId", (trainingPlan.Id).ToString());

                //插入默认训练课程 课程开始时间 = 训练计划开始时间
                trainingCourseService.SaveTrainingCourse(trainingPlan.Start_date);
                ts.Complete();
            }
        }