예제 #1
0
        public UserResponse GetUserList(UserRequest request)
        {
            UserResponse response = new UserResponse();
            using (var context = new hamptondwellEntities())
            {
                var User = (from a in context.Users.
                                   Where(
                                       a =>
                                       a.Active == request.Active &&
                                       (string.IsNullOrEmpty(request.FirstLetter) ||
                                        a.LastName.StartsWith(request.FirstLetter)) &&
                                       (string.IsNullOrEmpty(request.Email) || a.Email == request.Email))
                            select a);

                User = GetListSort(User, request);

                User = User.Skip(request.StartRowIndex).Take(request.MaximumRows);
                response.UserList = User.Select(a => new UserObject
                {
                    UserId = a.UserID,
                    FirstName = a.FirstName,
                    LastName = a.LastName,
                    Email = a.Email,
                    Active = a.Active,
                    Password = a.Password,
                    CreatedByUserId = a.CreatedBy_UserID ?? 0,
                    ModifiedByUserId = a.ModifiedBy_UserID ?? 0,
                    CreatedOn = a.CreatedOn ?? DateTime.MinValue,
                    ModifiedOn = a.ModifiedOn ?? DateTime.MinValue
                }).ToList();
                response.ResultSetCount = GetUserListCount(request);
            }
            return response;
        }
예제 #2
0
        public UserResponse GetUser(UserRequest request)
        {
            UserResponse response = new UserResponse();

            using (var context = new hamptondwellEntities())
            {
                var user = context.Users.
                    Where(u =>
                        (string.IsNullOrEmpty(request.Email) == false && u.Email == request.Email) && u.Active == true).FirstOrDefault();

                if (user == null)
                    return response;

                response.User = new UserObject()
                {
                    UserId = user.UserID,
                    Active = user.Active,
                    Email = user.Email,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Password = user.Password,
                    CreatedByUserId = user.CreatedBy_UserID ?? 0,
                    ModifiedByUserId = user.ModifiedBy_UserID ?? 0,
                    CreatedOn = user.CreatedOn ?? DateTime.MinValue,
                    ModifiedOn = user.ModifiedOn ?? DateTime.MinValue
                }
                ;
            }
            return response;
        }
예제 #3
0
        public UserResponse GetUserById(UserRequest request)
        {
            UserResponse response = new UserResponse();
            using (var context = new hamptondwellEntities())
            {
                var user = context.Users.
                    Where(u => u.UserID == request.UserId).FirstOrDefault();

                response.User = new UserObject()
                {
                    UserId = user.UserID,
                    Active = user.Active,
                    Email = user.Email,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Password = user.Password,
                    CreatedByUserId = user.CreatedBy_UserID ?? 0,
                    ModifiedByUserId = user.ModifiedBy_UserID ?? 0,
                    CreatedOn = user.CreatedOn ?? DateTime.MinValue,
                    ModifiedOn = user.ModifiedOn ?? DateTime.MinValue
                }
                ;
            }
            return response;
        }
예제 #4
0
        public UserResponse Save(UserRequest request)
        {
            UserResponse response = new UserResponse();
            using (var context = new hamptondwellEntities())
            {
                var user = context.Users.
                    Where(u => u.UserID == request.UserId).FirstOrDefault();

                user = user ?? new User();

                user.Email = request.Email;
                user.Active = request.Active;
                user.FirstName = request.FirstName;
                user.LastName = request.LastName;
                user.ModifiedBy_UserID = request.ModifiedBy;
                user.ModifiedOn = DateTime.UtcNow;

                if (user.UserID == 0 || string.IsNullOrEmpty(request.Password) == false)
                {
                    user.Password = request.Password;
                }
                if (user.UserID == 0)
                {
                    user.CreatedBy_UserID = request.CreatedBy;
                    user.CreatedOn = DateTime.UtcNow;

                    context.AddObject("Users", user);
                }
                context.SaveChanges();

                response.User = new UserObject()
                {
                    UserId = user.UserID,
                    Active = user.Active,
                    Email = user.Email,
                    FirstName = user.FirstName,
                    LastName = user.LastName,
                    Password = user.Password,
                    CreatedOn = user.CreatedOn.Value,
                    ModifiedOn = user.ModifiedOn.Value
                }
                ;
            }
            return response;
        }