public ActionResult Update(PublicCourseInfo model)
 {
     LogHelper.Info("PublicCourseInfoController->Update");
     using (ClassScheduleDBEntities db = new ClassScheduleDBEntities())
     {
         ResponseMessage msg = new ResponseMessage();
         try
         {
             //bool isExisted = db.PublicCourseInfo.Any(p => p.ID != model.ID && p.LoginName == model.LoginName);
             //if (isExisted)
             //{
             //    msg.Status = false;
             //    msg.Result = "700";
             //    return Json(msg, JsonRequestBehavior.AllowGet);
             //}
             db.PublicCourseInfo.Attach(model);
             db.Entry(model).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             msg.Status = true;
         }
         catch (Exception e)
         {
             msg.Status = false;
             msg.Result = "500";
         }
         return(Json(msg, JsonRequestBehavior.AllowGet));
     }
 }
 public ActionResult Add(PublicBox model)
 {
     using (ClassScheduleDBEntities db = new ClassScheduleDBEntities())
     {
         ResponseMessage msg = new ResponseMessage();
         try
         {
             bool isExisted = db.PublicBox.Any(p => p.LoginName == model.LoginName);
             if (isExisted)
             {
                 msg.Status = false;
                 msg.Result = "800";
                 return(Json(msg, JsonRequestBehavior.AllowGet));
             }
             var entity = db.PublicBox.Add(model);
             db.SaveChanges();
             //"家庭日记"默认增加
             PublicCourseInfoController pci      = new PublicCourseInfoController();
             PublicCourseInfo           pciModel = new PublicCourseInfo();
             if (model.PublicBoxType == (int)EnumUnit.PublicBoxTypeEnum.Class)
             {
                 pciModel.Name = "班级日记";
             }
             else
             {
                 pciModel.Name = "家庭日记";
             }
             pciModel.OpenID      = model.OpenID;
             pciModel.PublicBoxID = entity.ID;
             pciModel.DefaultType = (int)EnumUnit.PublicCourseInfoDefaultEnum.Diary;
             pci.Add(pciModel);
             msg.Status = true;
         }
         catch (Exception e)
         {
             msg.Status = false;
             msg.Result = "500";
         }
         return(Json(msg, JsonRequestBehavior.AllowGet));
     }
 }
        public ActionResult Add(PublicCourseInfo model)
        {
            using (ClassScheduleDBEntities db = new ClassScheduleDBEntities())
            {
                ResponseMessage msg = new ResponseMessage();
                try
                {
                    //bool isExisted = db.PublicCourseInfo.Any(p => p.LoginName == model.LoginName);
                    //if (isExisted)
                    //{
                    //    msg.Status = false;
                    //    msg.Result = "800";
                    //    return Json(msg, JsonRequestBehavior.AllowGet);
                    //}
                    var entity = db.PublicCourseInfo.Add(model);
                    db.SaveChanges();
                    //初始化课程
                    var defaultCourseList = db.DefaultCourse.Where(p => p.AppClass == ApplicationConstant.Course).OrderBy(p => p.Sort).ToList();
                    db.ChildrenStandardCourse.AddRange(defaultCourseList.Select(x => new ChildrenStandardCourse()
                    {
                        PublicCourseInfoID = entity.ID,
                        CourseName         = x.CourseName,
                        Sort = x.Sort
                    }));
                    db.SaveChanges();

                    msg.Status = true;
                }
                catch (Exception e)
                {
                    msg.Status = false;
                    msg.Result = "500";
                }
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }