public ActionResult Edit(Traning_Detail model)
        {
            PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL();

            //ViewBag.TrainingObjectData = bll.GetTraningObject();
            //ViewBag.SubjectData = bll.GetSubject();
            //ViewBag.StudyLevelData = bll.GetStudyLevel();
            //ViewBag.TrainingFormData = bll.GetTrainingForm();
            //ViewBag.TeacherTitleData = bll.GetTeacherTitle();
            //ViewBag.TrainingFeildData = bll.GetTrainingField("Delflag=0 and IsSpec=0", "");
            //ViewBag.TrainingCategoryData = bll.GetTrainingCategory("Delflag=0 and Field=" + model.TraingField, "");
            //ViewBag.TrainingTopicData = bll.GetTrainingTopic("Delflag=0 and CategoryId=" + model.TraingCategory, "");
            //DataTable attachData = bll.GetAttachTable("Delflag=0 and TraningId=" + model.Id, "");
            //ViewBag.AttachData = attachData;
            //ViewBag.OutCourseTypeData = bll.GetOutCourseType("Delflag=0", "");

            if (model.TraingCategory == 0)
            {
                TempData["Msg"] = "课程小类不能为空!";
                return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
            }

            if (model.TraingTopic == null || model.TraingTopic == 0)
            {
                TempData["Msg"] = "课程主题不能为空!";
                return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
            }

            if (string.IsNullOrEmpty(model.TeacherName))
            {
                TempData["Msg"] = "请输入讲师名称!";
                return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
            }

            if (string.IsNullOrEmpty(model.TeacherFrom))
            {
                TempData["Msg"] = "请输入讲师来自什么地方!";
                return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
            }

            string msg = "";

            if (model.Title == null)
                model.Title = "";
            else
                model.Title = model.Title.Trim();
            //if (bll.CheckExists(model.Title.Replace("'", "''"), Convert.ToInt32(model.OrganId), model.Id))
            //{
            //    TempData["Msg"] = "课程名称已存在";
            //    return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
            //}

            int picType = Code.ExtendHelper.ToInt(Request["PicType"]);
            if (picType == 1)//选择提供的图片
            {
                model.Pic = Request["PicValue"];
            }
            if (picType == 2)//选择上传的图片
            {
                HttpPostedFileBase pic = Request.Files["Pic"];
                string picPath = Code.UploadCore.UploadImage(pic, ref msg);
                if (picPath == "")
                {
                    TempData["Msg"] = msg;
                    return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
                }
                model.Pic = picPath;
            }

            if (Request.Files["TeacherPic"] != null)
            {
                if (Request.Files["TeacherPic"].ContentLength > 0)
                {
                    string teacherPicPath = Code.UploadCore.UploadImage(Request.Files["TeacherPic"], ref msg);
                    if (teacherPicPath == "")
                    {
                        TempData["Msg"] = msg;
                        return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
                    }
                    model.TeacherPic = teacherPicPath;
                }
                else
                {
                    model.TeacherPic = Request["TeacherPicValue"];
                }
            }
            else
            {
                model.TeacherPic = Request["TeacherPicValue"];
            }

            if (model.Range == 1)//区级时更新上级机构Id
                model.ParentOrganId = bll.GetParentOrganId(Convert.ToInt32(model.OrganId));
            if (model.Range == 2)//市级
                model.ParentOrganId = null;
            int outCourseType = Code.ExtendHelper.ToInt(Request["OutCourseType"]);
            if (model.OutSideType == -1)//内部平台
            {
                model.OutSideLink = null;
                model.OutSideContent = null;
            }
            else//外部平台
            {
                model.OutSideType = outCourseType;
            }

            using (TransactionScope trans = new TransactionScope())
            {
                try
                {
                    //更新培训
                    bll.UpdateTrainingDetail(model);

                    //更新附件
                    DataTable attach = bll.GetAttachTable("Delflag=0 and TraningId=" + model.Id, "");
                    List<string> attachIdList = new List<string>();
                    if (!string.IsNullOrEmpty(Request["AttachPathList"]))
                    {
                        foreach (string s in Request["AttachPathList"].Split(':'))
                        {
                            string[] file = s.Split('|');
                            if (file[0] == "0")
                            {
                                DataRow row = attach.NewRow();
                                row["Id"] = file[0];
                                row["TraningId"] = model.Id;
                                row["Title"] = file[1].Replace("'", "''");
                                row["Link"] = file[2];
                                row["Sort"] = 50;
                                row["Display"] = 1;
                                row["Delflag"] = 0;
                                row["CreateDate"] = DateTime.Now;
                                attach.Rows.Add(row);
                            }
                            else
                            {
                                attachIdList.Add(file[0]);
                            }
                        }
                    }
                    foreach (DataRow row in attach.Rows)
                    {
                        if (row.RowState == DataRowState.Unchanged && !attachIdList.Contains(row["Id"].ToString()))
                            row.Delete();
                    }
                    bll.BatchAttach(attach);

                    trans.Complete();
                    return RedirectToAction("List");
                }
                catch (Exception)
                {
                    TempData["Msg"] = "保存失败!";
                    return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id));
                }
            }
        }