Beispiel #1
0
        public JsonResult DeleteMessage(int messageID)
        {
            CheckUserData(out int userID, out int userAccess);
            ReturnJSON returnJSON = new ReturnJSON()
            {
                isOK = false,
                msg  = string.Empty
            };

            if (userID == 0)
            {
                returnJSON.msg += "<br/> * 請先登入";
            }
            else
            {
                try
                {
                    var message = messageBoardEntities.Message.Find(messageID);
                    message.MessageStatus = false;
                    messageBoardEntities.SaveChanges();
                    returnJSON.msg  = "文章刪除成功";
                    returnJSON.isOK = true;
                }
                catch (Exception err)
                {
                    LogTool.DoErrorLog($"#{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff")}:{err.Message}\r\n");
                    returnJSON.msg += "<br/> * 刪除文章時發生錯誤";
                }
            }

            return(Json(returnJSON, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult AddMessage(string content, int majorID)
        {
            CheckUserData(out int userID, out int userAccess);
            List <HttpPostedFileBase> postFile = new List <HttpPostedFileBase>();
            ReturnJSON returnJSON = new ReturnJSON()
            {
                isOK = false,
                msg  = string.Empty
            };

            returnJSON.msg = CheckCreateMesaage(content, userID);
            if (Request.Files.Count > 0)
            {
                postFile.Add(Request.Files[0]);
                var fileCheck = PicTool.CheckUplaodFiles(postFile[0], @"\.(?i:jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga|svg|jpeg2000)$", 1);
                if (!fileCheck.Item1)
                {
                    foreach (var item in fileCheck.Item2)
                    {
                        returnJSON.msg += $"<br/> * {item}";
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(returnJSON.msg))
            {
                try
                {
                    Message message;
                    if (majorID == 0)   // 建立新主題
                    {
                        MajorMessageList majorMessage = InsertMajorMessage(userID);
                        InsertMessage(content, userID, majorMessage.MajorID, out message);
                    }
                    else
                    {                   // 回覆留言
                        InsertMessage(content, userID, majorID, out message);
                    }

                    // 儲存圖片
                    if (postFile.Count > 0)
                    {
                        PicTool.SaveMessagePic(postFile[0], userID, message.MessageID);
                    }

                    returnJSON.isOK = true;
                    returnJSON.msg  = "文章新增成功";
                }
                catch (Exception err)
                {
                    LogTool.DoErrorLog($"#{DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff")}:{err.Message}\r\n");
                    returnJSON.msg = "<br/> * 儲存時發生錯誤";
                }
            }

            return(Json(returnJSON, JsonRequestBehavior.AllowGet));
        }