Пример #1
0
 public ActionResult Edit([Bind(Include = "Id,Count,Limit,Location,Name,StartTime,EndTime,Content,Status")] CourseOperation courseOperation)
 {
     if (ModelState.IsValid && courseOperation !=null)
     {
         if (courseOperation.Content.Length<=50)
         {
             courseOperation.ShortContent = courseOperation.Content;
         }
         courseOperation.ShortContent = courseOperation.Content.Substring(0, 50);
         if (courseOperation.Students != null)
         {
             if (courseOperation.Students.Count > courseOperation.Limit)
             {
                 ViewData["ErrorInfo"] = "无法修改!新人数上限小于现有人数,请审核修改内容。";
                 return View();
             }
         }
         if (courseOperation.Edit())
         {
             if (courseOperation.Students != null)
             {
                 foreach (User user in courseOperation.Students)
                 {
                     string title = "课程修改通知";
                     string content = "您好,你选择的课程[" + courseOperation.Name + "]已被修改,请及时查看相关信息,并根据新的课程信息安排你的日程";
                     Message message = new Message(title, content, user.Id, 0,db);
                     if (!message.Publish())
                     {
                         ViewData["ErrorInfo"] = "无法给学生发布修改信息";
                         return View();
                     }
                 }
             }
             return RedirectToAction("Index");
         }
         ViewData["ErrorInfo"] = "无法修改!无法连接到服务器.";
         return View();
     }
     ViewData["ErrorInfo"] = "无法修改!对象不存在或无效。";
     return View();
 }
        public ActionResult Edit(RoomOperation roomOperation)
        {
            if (ModelState.IsValid && roomOperation != null)
            {
                var s = new HtmlSanitizer();
                roomOperation.Content = Server.HtmlDecode(s.Sanitize(Request.Params["ck"])); ;
                if (roomOperation.StartTime >= roomOperation.EndTime)
                {
                    TempData["Alert"] = "无法完成修改,开始时间晚于结束时间。";
                    return View();
                }
                if (roomOperation.Edit())
                {
                    var user = Extensions.GetContextUser(ref db);
                    var RoomRecords = roomOperation.RoomRecords;
                    if (RoomRecords != null)
                    {
                        var lastRecord = RoomRecords.Where(r => r.ActionTime.AddDays(7.0) > r.RoomOperation.StartTime);
                        if (RoomRecords != null && lastRecord != null)
                        {
                            string title = "场地修改通知";
                            string content = "您好,你选择的场地[" + roomOperation.Name + "]已被修改,请及时查看相关信息,并根据新的场地信息安排你的日程";
                            Message message = new Message(title, content, lastRecord.First().Receiver.Id, MessageType.System, db);
                            if (message.Publish())
                            {
                                return RedirectToAction("Index");
                            }
                            TempData["Alert"] = "无法给学生发布修改信息";
                        }
                    }
                }
                else
                    TempData["Alert"] = "修改失败!";
            }
            else
                TempData["Alert"] = "无法修改!对象不存在或无效。";

            return RedirectToAction("Index");
        }
 public ActionResult Edit([Bind(Include = "Id,Count,Limit,Location,Name,StartTime,EndTime,Content,Status")] CourseOperation courseOperation)
 {
     if (ModelState.IsValid && courseOperation != null)
     {
         if (courseOperation.StartTime >= courseOperation.EndTime)
         {
             TempData["Alert"] = "无法完成修改,开始时间晚于结束时间。";
             return View();
         }
         if (courseOperation.Students != null)
         {
             if (courseOperation.Students.Count > courseOperation.Limit)
             {
                 TempData["Alert"] = "无法修改!新人数上限小于现有人数,请审核修改内容。";
                 return View();
             }
         }
         if (courseOperation.Edit())
         {
             if (courseOperation.Students != null)
             {
                 foreach (User user in courseOperation.Students)
                 {
                     string title = "课程修改通知";
                     string content = "您好,你选择的课程[" + courseOperation.Name + "]已被修改,请及时查看相关信息,并根据新的课程信息安排你的日程";
                     Message message = new Message(title, content, user.Id, MessageType.System, db);
                     if (!message.Publish())
                     {
                         TempData["Alert"] = "无法给学生发布修改信息";
                         return View();
                     }
                 }
             }
             return RedirectToAction("Index");
         }
         TempData["Alert"] = "无法修改!无法连接到服务器.";
         return View();
     }
     TempData["Alert"] = "无法修改!对象不存在或无效。";
     return View();
 }