コード例 #1
0
        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");
        }
コード例 #2
0
 public bool Apply(Guid Id)
 {
     using (BaseDbContext db = new BaseDbContext())
     {
         try
         {
             var roomOperation = db.RoomOperations.Find(Id);
             if (roomOperation == null)
                 return false;
             Id = Guid.NewGuid();
             RoomOperation = roomOperation;
             ActionTime = DateTime.Now;
             Receiver = db.Users.Find(HttpContext.Current.User.Identity.GetUserId());
             RemarkContent = "";
             RemarkRate = RemarkType.None;
             Time = new DateTime(2000, 1, 1, 0, 0, 0);
             RoomOperation.Usable = false;
             db.RoomRecords.Add(this);
             db.SaveChanges();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
コード例 #3
0
 public bool Remark()
 {
     using (BaseDbContext db = new BaseDbContext())
     {
         try
         {
             User user = db.Users.Find(HttpContext.Current.User.Identity.GetUserId());
             RoomOperation = db.RoomOperations.First(t => t.Creator == user);
             Time = DateTime.Now;
             db.Entry(this).State = EntityState.Modified;
             db.SaveChanges();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
コード例 #4
0
ファイル: RoomModels.cs プロジェクト: Pyuuma/SITE
 public static bool Remark([Bind(Include = "Id,ActionTime,RemarkContent,RemarkRate,Time")] RoomRecord RoomRecord)
 {
     using (BaseDbContext db = new BaseDbContext())
     {
         try
         {
             User user = db.Users.Find(HttpContext.Current.User.Identity.GetUserId());
             RoomRecord.RoomOperation = db.RoomOperations.First(t => t.Creator == user);
             RoomRecord.Time = DateTime.Now;
             db.Entry(RoomRecord).State = EntityState.Modified;
             db.SaveChanges();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }