Пример #1
0
        public string Add()
        {
            string name = Request["Name"];
            string KeyWord = Request["KeyWord"];
            string Content = Request["Content"];
            string ReceiveRange = Request["ReceiveRange"];
            string IsPublish = Request["IsPublish"];
            string ReceiveRangeIds =HttpUtility.UrlDecode ( Request["ReceiveRangeIds"]);
            string MsgType = Request["MsgType"];

            var model = new NoticeMessage();
            model.Id = Guid.NewGuid();
            model.Name = name;
            model.KeyWord = KeyWord;
            model.ReceiveRange = ReceiveRange;
            model.Content = Content;
            model.IsPublish = IsPublish=="true";
            model.ReceiveRangeIds = ReceiveRangeIds;
            model.MsgType = string.IsNullOrEmpty(MsgType) ? 1 : Convert.ToInt32(MsgType);

            if (model.IsPublish)
            {
                model.ReleaseId = CurrentUser.UserId;
                model.ReleaseName = CurrentUser.UserName;
                model.ReleaseTime = System.DateTime.Now;
            }
            model.CreateId = CurrentUser.UserId;
            model.CreateName = CurrentUser.UserName;
            model.CreateTime = System.DateTime.Now;
            model.IsValid = true;
            try
            {
                unitOfWork.NoticeMessageBLL.InsertEntity(model);
                unitOfWork.Save();
                return "";
            }
            catch (Exception ex)
            {
                Log.Error("保存实时消息异常:" + ex.Message, ex);
                return "系统异常,请联系管理员!";
            }
        }
Пример #2
0
        public string Save(HttpPostedFileBase fileData)
        {
            string name = Request["Name"];
            string KeyWord = Request["KeyWord"];
            string Content = Request["Content"];
            string ReceiveRange = Request["ReceiveRange"];
            string ReceiveRangeIds = HttpUtility.UrlDecode(Request["ReceiveRangeIds"]);
            string MsgType = Request["MsgType"];
            string IsPublish = Request["IsPublish"];
            string t = Request["t"];

            if (t == "1") //new
            {
                var model = new NoticeMessage();
                model.Id = Guid.NewGuid();
                model.Name = name;
                model.KeyWord = KeyWord;
                model.ReceiveRange = ReceiveRange;
                model.ReceiveRangeIds = ReceiveRangeIds;
                model.MsgType = string.IsNullOrEmpty(MsgType)?1:Convert.ToInt32(MsgType);
                model.Content = Content;
                model.IsPublish = IsPublish == "true";

                if (model.IsPublish)
                {
                    model.ReleaseId = CurrentUser.UserId;
                    model.ReleaseName = CurrentUser.UserName;
                    model.ReleaseTime = System.DateTime.Now;
                }
                model.CreateId = CurrentUser.UserId;
                model.CreateName = CurrentUser.UserName;
                model.CreateTime = System.DateTime.Now;
                model.IsValid = true;
                if (fileData != null)
                {
                    string filePath = Server.MapPath("~/FileUpload/TimeMessage/");
                    string fileName = Path.GetFileName(fileData.FileName); //原始文件名称
                    string fileExtension = Path.GetExtension(fileName); //文件扩展名
                    string saveName = model.Id + fileExtension; //保存文件名称
                    fileData.SaveAs(filePath + saveName);
                    model.AttachUrl = "../../FileUpload/TimeMessage/" + saveName;
                    model.AttachName = fileName;
                }
                try
                {
                    unitOfWork.NoticeMessageBLL.InsertEntity(model);
                    unitOfWork.Save();
                    return "";
                }
                catch (Exception ex)
                {
                    Log.Error("保存实时消息异常:" + ex.Message, ex);
                    return "系统异常,请联系管理员!";
                }
            }
            else
            {
                string id = Request["Id"];
                var model = unitOfWork.NoticeMessageBLL.GetEntityByID(new Guid(id));
                if (model != null)
                {
                    if (model.IsPublish)
                    {
                        return "已发布的消息不允许编辑!";
                    }
                    else
                    {
                        model.Name = name;
                        model.KeyWord = KeyWord;
                        model.ReceiveRange = ReceiveRange;
                        model.ReceiveRangeIds = ReceiveRangeIds;
                        model.MsgType = string.IsNullOrEmpty(MsgType) ? 1 : Convert.ToInt32(MsgType);
                        model.Content = Content;
                        model.IsPublish = IsPublish == "true";

                        if (model.IsPublish)
                        {
                            model.ReleaseId = CurrentUser.UserId;
                            model.ReleaseName = CurrentUser.UserName;
                            model.ReleaseTime = System.DateTime.Now;
                        }
                        model.LastModifyId = CurrentUser.UserId;
                        model.LastModifyName = CurrentUser.UserName;
                        model.LastModifyTime = System.DateTime.Now;
                        if (fileData != null)
                        {
                            string filePath = Server.MapPath("~/FileUpload/TimeMessage/");
                            string fileName = Path.GetFileName(fileData.FileName); //原始文件名称
                            string fileExtension = Path.GetExtension(fileName); //文件扩展名
                            string saveName = model.Id + fileExtension; //保存文件名称
                            fileData.SaveAs(filePath + saveName);
                            model.AttachName = fileName;
                            model.AttachUrl = "../../FileUpload/TimeMessage/" + saveName;
                        }
                    }
                }
                else
                {
                    return "参数错误!";
                }

                try
                {
                    unitOfWork.NoticeMessageBLL.UpdateEntity(model);
                    unitOfWork.Save();
                    return "";
                }
                catch (Exception ex)
                {
                    Log.Error("修改实时消息异常:" + ex.Message, ex);
                    return "系统异常,请联系管理员!";
                }
            }
        }