Beispiel #1
0
        public ActionResult MessageIng(string msg)
        {
            MessageServices     msgServices = new MessageServices();
            JsonResult <string> result      = new JsonResult <string>();
            string userip = UserAddress.GetUserAddress();
            //10分钟内,同一ip只可留言一次
            var newMsg = msgServices.query.Where(q => q.user_ip == userip).OrderByDescending(q => q.msg_time).FirstOrDefault();

            if (newMsg != null && ((TimeSpan)(DateTime.Now - newMsg.msg_time)).TotalMinutes < 10)
            {
                result.Fail("已留言," + (10 - ((TimeSpan)(DateTime.Now - newMsg.msg_time)).TotalMinutes).ToString("F0") + "分钟内无法再次留言");
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            message add = new message();

            add.is_del   = false;
            add.msg_time = DateTime.Now;
            add.content  = msg;
            add.user_ip  = userip;
            if (msgServices.Add(add) > 0)
            {
                result.Success();
            }
            else
            {
                result.Fail("留言失败");
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(MessageModels ms)
        {
            user c = us.GetById((int)Session["LogedUserid"]);

            message msg = new message
            {
                subject    = ms.subject,
                date       = System.DateTime.Now,
                idSender   = (int)Session["LogedUserid"],
                text       = ms.text,
                idReceiver = (int)ms.UserId
            };

            mss.Add(msg);
            mss.SaveChange();

            return(RedirectToAction("ListMessage"));
        }
Beispiel #3
0
        public JsonResult EditMessage(Message model)
        {
            try
            {
                model.UserID   = GetLoginUser.RecordID;
                model.UserName = GetLoginUser.UserName;
                if (string.IsNullOrWhiteSpace(model.RecordID))
                {
                    model.UserID   = GetLoginUser.RecordID;
                    model.UserName = GetLoginUser.UserName;
                    bool result = MessageServices.Add(model);
                    if (!result)
                    {
                        throw new MyException("保存失败");
                    }
                }
                else
                {
                    bool result = MessageServices.Update(model);
                    if (!result)
                    {
                        throw new MyException("保存失败");
                    }
                }


                return(Json(MyResult.Success()));
            }
            catch (MyException ex)
            {
                return(Json(MyResult.Error(ex.Message)));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptions(ex, "保存黑名单信息失败");
                return(Json(MyResult.Error("保存失败")));
            }
        }