public ActionResult Users(UsersInfo usersInfo)
        {
            if (usersInfo == null) return Json(new FeedbackInfo { Success = -1, Message = "获取实体出错" });
            if (string.IsNullOrWhiteSpace(usersInfo.Name)) return Json(new FeedbackInfo { Success = -1, Message = "请输入登陆名称" });
            if (string.IsNullOrWhiteSpace(usersInfo.Email)) return Json(new FeedbackInfo { Success = -1, Message = "请输入邮箱" });
            usersInfo.Phone = string.IsNullOrWhiteSpace(usersInfo.Phone) == true ? "" : usersInfo.Phone;
            usersInfo.Password = string.IsNullOrWhiteSpace(usersInfo.Password) == true ? "" : usersInfo.Password;
            usersInfo.RealName = string.IsNullOrWhiteSpace(usersInfo.RealName) == true ? "" : usersInfo.RealName;
            usersInfo.Photo = string.IsNullOrWhiteSpace(usersInfo.Photo) == true ? "" : usersInfo.Photo;
            //新建
            int result = 0;
            if (usersInfo.ID == 0)
            {
                usersInfo.Date = DateTime.Now;
                result = Start.DatabaseProvider.Instance().InsertUser(usersInfo);
                if (result == 1)
                    return Json(new FeedbackInfo { Success = 1, Message = "添加成功" });
                else
                    return Json(new FeedbackInfo { Success = -1, Message = "添加失败" });
            }
            else //编辑
            {
                result = Start.DatabaseProvider.Instance().UpdateUser(usersInfo);
                if (result == 1)
                    return Json(new FeedbackInfo { Success = 1, Message = "修改成功" });
                else
                    return Json(new FeedbackInfo { Success = -1, Message = "修改失败" });
            }

        }
 public ActionResult Users(int? id)
 {
     UsersInfo usersInfo = null;
     if (id != null && id.Value != 0) usersInfo = Start.DatabaseProvider.Instance().GetUserByID(id.Value);
     if (usersInfo == null) usersInfo = new UsersInfo ();
     return View(usersInfo);
 }
Example #3
0
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <param name="userInfo">用户实体</param>
        /// <param name="pageInfo">分页实体</param>
        /// <returns></returns>
        public IList<UsersInfo> GetUser(UsersInfo userInfo, PageInfo pageInfo)
        {
            using (DataContextDB DB = new DataContextDB())
            {
                IQueryable<UsersInfo> userInfos =
                    (
                        from item in DB.GetTable<UsersInfo>()
                        orderby item.ID descending
                        select item
                    );
                if (userInfo != null && userInfo.ID != 0)
                    userInfos = userInfos.Where<UsersInfo>(m => m.ID == userInfo.ID);
                if (userInfo != null && !string.IsNullOrEmpty(userInfo.Name))
                    userInfos = userInfos.Where<UsersInfo>(m => m.Name.Contains(userInfo.Name));
                if (userInfo != null && userInfo.UserGroup != 0)
                    userInfos = userInfos.Where<UsersInfo>(m => m.UserGroup == userInfo.UserGroup);

                if (pageInfo != null)
                {
                    pageInfo.TotalRecord = userInfos.Count();
                    return userInfos.Skip(pageInfo.PageSize * (pageInfo.PageIndex - 1)).Take(pageInfo.PageSize).ToList<UsersInfo>();
                }
                else
                    return userInfos.ToList<UsersInfo>();
            }
        }
 public ActionResult UsersList(string name, int pageIndex = 1)
 {
     PageInfo pageInfo = new PageInfo { PageIndex = pageIndex};
     UsersInfo usersInfo = new UsersInfo {Name = name };
     IList<UsersInfo> usersInfos = Start.DatabaseProvider.Instance().GetUser(usersInfo, pageInfo);
     PagedList<UsersInfo> pagedList = new PagedList<UsersInfo>(usersInfos, pageInfo.PageIndex, pageInfo.PageSize, pageInfo.TotalRecord);
     ViewBag.UsresInfo = usersInfo;
     return View(pagedList);
 }
Example #5
0
 /// <summary>
 /// 添加用户
 /// </summary>
 /// <param name="userInfo">用户实体</param>
 public int InsertUser(UsersInfo userInfo)
 {
     using (DataContextDB DB = new DataContextDB())
     {
         try
         {
             DB.GetTable<UsersInfo>().InsertOnSubmit(userInfo);
             DB.SubmitChanges();
             return 1;
         }
         catch (Exception e)
         {
             string error = e.Message;
             return -1;
         }
     }
 }
Example #6
0
 /// <summary>
 /// 修改用户
 /// </summary>
 /// <param name="userInfo">用户实体</param>
 public int UpdateUser(UsersInfo userInfo)
 {
     using (DataContextDB DB = new DataContextDB())
     {
         try
         {
             DB.GetTable<UsersInfo>().Attach(userInfo, true);
             DB.SubmitChanges();
             return 1;
         }
         catch (Exception e)
         {
             string error = e.Message;
             return -1;
         }
     }
 }