Exemple #1
0
        /// <summary>
        /// 作者:Primo
        /// 时间:2014.07.02
        /// 描述:创建课程附件
        /// </summary>
        /// <param name="courseware"></param>
        /// <param name="coursewareDetail"></param>
        /// <returns></returns>
        public static bool CreateCourseware(Courseware courseware, CoursewareDetail coursewareDetail)
        {
            using (var tran = new TransactionScope())
            {
                using (var edb = new EmeEntities())
                {
                    try
                    {
                        edb.Entry(courseware).State = EntityState.Added;
                        edb.SaveChanges();
                        coursewareDetail.CoursewareId = courseware.Id;
                        edb.Entry(coursewareDetail).State = EntityState.Added;
                        var result = edb.SaveChanges() > 0;

                        tran.Complete();

                        return result;
                    }
                    catch (Exception e)
                    {
                        tran.Dispose();

                        // 异常日志消息队列
                        Common.MSMQ.QueueManager.AddExceptionLog(new ExceptionLogs()
                        {
                            ExceptionType = CommonHelper.To<int>(ExceptionType.Function),
                            Message = string.Format("CourseBLL-CreateCourseware:{0};{1};{2}", e.Message, e.InnerException.Message, e.HelpLink),
                            IsTreat = false,
                            CreateBy = courseware.CreateBy,
                            CreateTime = DateTime.Now
                        });

                        return false;
                    }
                }
            }
        }
        public JsonResult CreateCoursewareDetail(int courseId, int userType, string cName, string fileCode, string fileName, string fileExt, int fileSize)
        {
            var modelCourseware = new Courseware()
            {
                CoursewareTypeId = 1,
                CName = cName,
                FileCode = fileCode.Replace(fileExt, ""),
                FileName = fileCode,
                FileExt = fileExt,
                FileSize = fileSize,
                Status = ConvertEnum.StatusTypeForActive,
                CreateBy = LoginUserManager.CurrLoginUser.UserId,
                CreateTime = DateTime.Now
            };

            var modelCoursewareDetail = new CoursewareDetail()
            {
                CourseId = courseId,
                UserType = userType,
                CoursewareId = 0,
                Status = ConvertEnum.StatusTypeForActive,
                CreateBy = LoginUserManager.CurrLoginUser.UserId,
                CreateTime = DateTime.Now
            };

            var result = CourseBLL.CreateCourseware(modelCourseware, modelCoursewareDetail);

            var msg = result ? "上传成功!" : "上传失败!";
            return Json(new { status = result, msg = msg }, JsonRequestBehavior.DenyGet);
        }