/// <summary>
 /// 修改短信配置
 /// </summary>
 /// <param name="messageProfileInfo">短信配置实体</param>
 public int UpdateMessageProfile(MessageProfileInfo messageProfileInfo)
 {
     using (DataContextDB DB = new DataContextDB())
     {
         try
         {
             DB.GetTable<MessageProfileInfo>().Attach(messageProfileInfo, true);
             DB.SubmitChanges();
             return 1;
         }
         catch (Exception e)
         {
             string error = e.Message;
             return -1;
         }
     }
 }
 /// <summary>
 /// 添加短信配置
 /// </summary>
 /// <param name="messageProfileInfo">短信配置实体</param>
 public int InsertMessageProfile(MessageProfileInfo messageProfileInfo)
 {
     using (DataContextDB DB = new DataContextDB())
     {
         try
         {
             DB.GetTable<MessageProfileInfo>().InsertOnSubmit(messageProfileInfo);
             DB.SubmitChanges();
             return 1;
         }
         catch (Exception e)
         {
             string error = e.Message;
             return -1;
         }
     }
 }
        /// <summary>
        /// 获取短信配置
        /// </summary>
        /// <param name="messageProfileInfo">短信配置实体</param>
        /// <param name="pageInfo">分页实体</param>
        /// <returns></returns>
        public IList<MessageProfileInfo> GetMessageProfile(MessageProfileInfo messageProfileInfo, PageInfo pageInfo)
        {
            using (DataContextDB DB = new DataContextDB())
            {
                IQueryable<MessageProfileInfo> messageProfileInfos =
                    (
                        from item in DB.GetTable<MessageProfileInfo>()
                        orderby item.ID descending
                        select item
                    );
                if (messageProfileInfo != null && messageProfileInfo.ID != 0)
                    messageProfileInfos = messageProfileInfos.Where<MessageProfileInfo>(m => m.ID == messageProfileInfo.ID);
                if (messageProfileInfo != null && messageProfileInfo.UserID != 0)
                    messageProfileInfos = messageProfileInfos.Where<MessageProfileInfo>(m => m.UserID == messageProfileInfo.UserID);

                if (pageInfo != null)
                {
                    pageInfo.TotalRecord = messageProfileInfos.Count();
                    return messageProfileInfos.Skip(pageInfo.PageSize * (pageInfo.PageIndex - 1)).Take(pageInfo.PageSize).ToList<MessageProfileInfo>();
                }
                else
                    return messageProfileInfos.ToList<MessageProfileInfo>();
            }
        }
        public ActionResult MessageProfile(MessageProfileInfo messageProfileInfo)
        {
            if (messageProfileInfo == null) return Json(new FeedbackInfo { Success = -1, Message = "获取实体出错" });
            if (messageProfileInfo.UserID == 0) return Json(new FeedbackInfo { Success = -1, Message = "请输入用户编号" });
            if (string.IsNullOrWhiteSpace(messageProfileInfo.Name)) return Json(new FeedbackInfo { Success = -1, Message = "请输入短信名称" });
            if (string.IsNullOrWhiteSpace(messageProfileInfo.Memo)) return Json(new FeedbackInfo { Success = -1, Message = "请输入短信内容" });
            //新建
            int result = 0;
            if (messageProfileInfo.ID == 0)
            {
                result = Start.DatabaseProvider.Instance().InsertMessageProfile(messageProfileInfo);
                if (result == 1)
                    return Json(new FeedbackInfo { Success = 1, Message = "添加成功" });
                else
                    return Json(new FeedbackInfo { Success = -1, Message = "添加失败" });
            }
            else //编辑
            {
                result = Start.DatabaseProvider.Instance().UpdateMessageProfile(messageProfileInfo);
                if (result == 1)
                    return Json(new FeedbackInfo { Success = 1, Message = "修改成功" });
                else
                    return Json(new FeedbackInfo { Success = -1, Message = "修改失败" });
            }

        }
 public ActionResult MessageProfile(int? id)
 {
     MessageProfileInfo messageProfileInfo = null;
     if (id != null && id.Value != 0) messageProfileInfo = Start.DatabaseProvider.Instance().GetMessageProfileByID(id.Value);
     if (messageProfileInfo == null) messageProfileInfo = new MessageProfileInfo();
     return View(messageProfileInfo);
 }
 public ActionResult MessageProfileList(int userID = 0, int pageIndex = 1)
 {
     PageInfo pageInfo = new PageInfo { PageIndex = pageIndex };
     MessageProfileInfo messageProfileInfo = new MessageProfileInfo { UserID = userID };
     IList<MessageProfileInfo> messageProfileInfos = Start.DatabaseProvider.Instance().GetMessageProfile(messageProfileInfo, pageInfo);
     PagedList<MessageProfileInfo> pagedList = new PagedList<MessageProfileInfo>(messageProfileInfos, pageInfo.PageIndex, pageInfo.PageSize, pageInfo.TotalRecord);
     ViewBag.MessageProfileInfo = messageProfileInfo;
     return View(pagedList);
 }