Example #1
0
        public User AddUser(User user)
        {
            if (user == null)
            {
                throw new MobileException("非法的user参数,user 不能为空.");
            }

            using (var dbContext = new DataEntities())
            {
                user.CreatedDate = DateTime.Now;
                user.LastUpdatedDate = DateTime.Now;
                dbContext.Users.AddObject(user);
                dbContext.SaveChanges();
            }

            return user;
        }
Example #2
0
        public ActionResult EditUserInManage(UserListViewModel model)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(model.EditName) || string.IsNullOrWhiteSpace(model.EditCity))
                {
                    throw new Exception("真实姓名和城市不能为空。");
                }

                User user = new User{
                    UserName = model.SelectedLoginName,
                    FullName = model.EditName,
                    Phone = model.EditPhone,
                    City = model.EditCity,
                    Description = model.EditDescription
                };

                UserRepository ur = new UserRepository();
                ur.UpdateUser(user);
                model.QueryData();
                return View("Manage", model);

            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(model);
            }
        }
Example #3
0
 /// <summary>
 /// 创建新的 User 对象。
 /// </summary>
 /// <param name="id">ID 属性的初始值。</param>
 /// <param name="userType">UserType 属性的初始值。</param>
 /// <param name="userName">UserName 属性的初始值。</param>
 /// <param name="password">Password 属性的初始值。</param>
 /// <param name="fullName">FullName 属性的初始值。</param>
 public static User CreateUser(global::System.Int32 id, global::System.Int32 userType, global::System.String userName, global::System.String password, global::System.String fullName)
 {
     User user = new User();
     user.ID = id;
     user.UserType = userType;
     user.UserName = userName;
     user.Password = password;
     user.FullName = fullName;
     return user;
 }
Example #4
0
 /// <summary>
 /// 用于向 Users EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
Example #5
0
        private UserModel ConvertDBUserToBizUser(User dbUser)
        {
            UserModel user = new UserModel()
            {
                LoginName = dbUser.UserName,
                Name = dbUser.FullName,
                UserType = dbUser.UserType,
                Address = dbUser.Address,
                City = dbUser.City,
                Province = dbUser.Province,
                Password = dbUser.Password,
                Phone = dbUser.Phone,
                Email = dbUser.Email,
                Description = dbUser.Description,
                CreatedBy = dbUser.CreatedBy,
                CreatedDate = dbUser.CreatedDate.HasValue? dbUser.CreatedDate.Value : DateTime.MinValue,
                LastUpdatedBy = dbUser.LastUpdatedBy,
                LastUpdatedDate = dbUser.LastUpdatedDate.HasValue ? dbUser.LastUpdatedDate.Value : DateTime.MinValue
            };

            return user;
        }
Example #6
0
        private User ConvertBizUserToDbUser(UserModel user)
        {
            User dbUser = new User()
            {
                UserName = user.LoginName,
                FullName = user.Name,
                UserType = user.UserType,
                Address = user.Address,
                City = user.City,
                Province = user.Province,
                Password = user.Password,
                Phone = user.Phone,
                Email = user.Email,
                Description = user.Description,
                CreatedBy = user.CreatedBy,
                LastUpdatedBy = user.LastUpdatedBy
            };

            return dbUser;
        }
Example #7
0
        public void UpdateUser(User user)
        {
            if (user == null || String.IsNullOrWhiteSpace(user.UserName))
            {
                throw new Exception("参数userName不能为空。");
            }

            using (var dbContext = new DataEntities())
            {
                var dbUser = dbContext.Users.Where(u => u.UserName.Equals(user.UserName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (dbUser == null)
                {
                    throw new Exception("该用户不存在!");
                }
                else
                {
                    dbUser.FullName = user.FullName;
                    dbUser.Phone = user.Phone;
                    dbUser.Description = user.Description;
                    dbUser.City = user.City;
                    dbContext.SaveChanges();
                }
            }
        }