public JsonResult CreateProductLevelCourseType(int productLevelId, string oldProductCourseTypeIdList, string newProductCourseTypeIdList)
        {
            var oldList = oldProductCourseTypeIdList.Trim().Split(',');
            var newList = newProductCourseTypeIdList.Trim().Split(',');

            List<string> oIdList = new List<string>();
            foreach (var oId in oldList)
            {
                if (!newList.Contains(oId) && oId != "")
                {
                    //需要删除
                    oIdList.Add(oId);
                }
            }

            List<ProductLevelCourseType> addProductLevelCourseType = new List<ProductLevelCourseType>();
            foreach (var productCourseType in newList)
            {
                if (!oldList.Contains(productCourseType) && productCourseType != "")
                {
                    var idAndType = productCourseType.Split('-');
                    //需要新增
                    var plct = new ProductLevelCourseType()
                    {
                        ProductLevelId = CommonHelper.To<int>(productLevelId),
                        ProductCourseTypeId = CommonHelper.To<int>(idAndType[0]),
                        Status = CommonHelper.To<int>(StatusType.Active),
                        SelectivityType = CommonHelper.To<int>(idAndType[1]),
                        CreateBy = LoginUserManager.CurrLoginUser.UserId,
                        CreateTime = DateTime.Now,
                        Courses = 0,
                        Students = 0
                    };
                    addProductLevelCourseType.Add(plct);
                }
            }

            var result = ProductBLL.CreateProductLevelCourseType(productLevelId, oldList, newList, addProductLevelCourseType, LoginUserManager.CurrLoginUser.UserId);
            var msg = result ? "更新成功!" : "更新失败!";
            return Json(new { status = result, msg = msg, productLevelId = productLevelId }, JsonRequestBehavior.DenyGet);
        }
Пример #2
0
        /// <summary>
        /// 作者:Raymond
        /// 日期:2014-3-5
        /// 描述:新增课程级别 、明细 
        /// </summary>
        /// <param name="pLevel"></param>
        /// <param name="requiredCourse"></param>
        /// <param name="electiveCourse"></param>
        /// <param name="createBy"></param>
        /// <returns></returns>
        public static bool AddProductLevel(ProductLevel pLevel, string requiredCourse, string electiveCourse, int createBy)
        {
            using (var edb = new EmeEntities())
            {
                try
                {
                    edb.Entry(pLevel).State = EntityState.Added;
                    var flag = edb.SaveChanges() > 0;

                    if (flag)
                    {
                        var productLevelId = pLevel.Id;
                        //处理必修课
                        if (requiredCourse.Length > 0)
                        {
                            var rList = requiredCourse.Split('&');
                            foreach (var item in rList)
                            {
                                var rListDetail = item.Split('^');
                                var pCourseTypeId = CommonHelper.To<int>(rListDetail[1]);
                                var courses = CommonHelper.To<int>(rListDetail[2]);
                                var students = CommonHelper.To<int>(rListDetail[3]);
                                var pLevelCourseType = new ProductLevelCourseType()
                                {
                                    ProductLevelId = productLevelId,
                                    ProductCourseTypeId = pCourseTypeId,
                                    SelectivityType = CommonHelper.To<int>(SelectivityType.Required),
                                    Courses = courses,
                                    Students = students,
                                    Status = CommonHelper.To<int>(StatusType.Active),
                                    CreateBy = createBy,
                                    CreateTime = DateTime.Now
                                };
                                edb.Entry(pLevelCourseType).State = EntityState.Added;
                            }
                        }
                        //处理选修课
                        if (electiveCourse.Length > 0)
                        {
                            var eList = electiveCourse.Split('&');
                            if (eList.Any())
                            {
                                foreach (var item in eList)
                                {
                                    var eListDetail = item.Split('^');
                                    var pCourseTypeId = CommonHelper.To<int>(eListDetail[1]);
                                    var courses = CommonHelper.To<int>(eListDetail[2]);
                                    var students = CommonHelper.To<int>(eListDetail[3]);
                                    var pLevelCourseType = new ProductLevelCourseType()
                                    {
                                        ProductLevelId = productLevelId,
                                        ProductCourseTypeId = pCourseTypeId,
                                        SelectivityType = CommonHelper.To<int>(SelectivityType.Elective),
                                        Courses = courses,
                                        Students = students,
                                        Status = CommonHelper.To<int>(StatusType.Active),
                                        CreateBy = createBy,
                                        CreateTime = DateTime.Now
                                    };
                                    edb.Entry(pLevelCourseType).State = EntityState.Added;
                                }
                            }
                        }
                    }
                    return edb.SaveChanges() > 0;
                }
                catch
                {
                    return false;
                }
            }
        }