public IActionResult Create(Message message)
 {
     if (ModelState.IsValid)
     {
         _context.Message.Add(message);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(message);
 }
        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");
        }
Example #3
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();
 }
 /// <summary>
 /// Create a new Message object.
 /// </summary>
 /// <param name="id">Initial value of the id property.</param>
 /// <param name="sessionToken">Initial value of the SessionToken property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="messageValue">Initial value of the MessageValue property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 public static Message CreateMessage(global::System.Int32 id, global::System.String sessionToken, global::System.Int32 type, global::System.String messageValue, global::System.DateTime dateCreated)
 {
     Message message = new Message();
     message.id = id;
     message.SessionToken = sessionToken;
     message.Type = type;
     message.MessageValue = messageValue;
     message.DateCreated = dateCreated;
     return message;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Messages EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToMessages(Message message)
 {
     base.AddObject("Messages", message);
 }
 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();
 }