Exemplo n.º 1
0
        public IEnumerable<DataModel.UserEntity> GetAll()
        {
            List<UserEntity> users = new List<UserEntity>();
            foreach (var item in dataContext.Users)
            {
                UserEntity user = new UserEntity();
                user.UserId = item.UserId;
                user.FirstName = item.FirstName;
                user.LastName = item.LastName;
                user.UserName = item.UserName;
                user.Password = item.Password;
                user.PositionId = item.PositionId;
                user.Email = item.Email;
                user.Position = new PositionEntity() { Description = item.Position.Description, PositionId = item.PositionId };

                foreach (var right in item.Rights)
                {
                    user.Rights.Add(new RightEntity() { RightId = right.RightId, Description = right.Description });
                }

                foreach (var project in item.Projects)
                {
                    user.Projects.Add(new ProjectEntity() { ProjectId = project.ProjectId, Description = project.Description });
                }
                users.Add(user);
            }
            return users;
        }
Exemplo n.º 2
0
        // POST api/User
        public HttpResponseMessage PostUser(UserEntity user)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
            if (user == null)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

            try
            {
                context.AddUser(user);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Exemplo n.º 3
0
        public UserEntity GetLonginUser(string username, string password)
        {
            var user = dataContext.Users.FirstOrDefault(c => (c.UserName == username | c.Email == username ) & c.Password == password);
            if (user != null)
            {
                UserEntity l_user = new UserEntity();

                l_user.UserId = user.UserId;
                l_user.FirstName = user.FirstName;
                l_user.LastName = user.LastName;
                l_user.UserName = user.UserName;
                l_user.Password = user.Password;
                l_user.PositionId = user.PositionId;
                l_user.Email = user.Email;
                l_user.Position = new PositionEntity()
                {
                    Description = user.Position.Description,
                    PositionId = user.PositionId
                };

                foreach (var right in user.Rights)
                {
                    l_user.Rights.Add(new RightEntity() { RightId = right.RightId, Description = right.Description });
                }

                foreach (var project in user.Projects)
                {
                    l_user.Projects.Add(new ProjectEntity() { ProjectId = project.ProjectId, Name = project.Name , Description = project.Description });
                }

                return l_user;
            }
            return null;
        }
Exemplo n.º 4
0
        public DataModel.UserEntity GetUserById(int id)
        {
            var user = dataContext.Users.FirstOrDefault(c => c.UserId == id);
            if (user != null)
            {
                UserEntity l_user = new UserEntity();

                l_user.UserId = user.UserId;
                l_user.FirstName = user.FirstName;
                l_user.LastName = user.LastName;
                l_user.UserName = user.UserName;
                l_user.Password = user.Password;
                l_user.PositionId = user.PositionId;
                l_user.Email = user.Email;
                l_user.Position = new PositionEntity()
                {
                    Description = user.Position.Description,
                    PositionId = user.PositionId
                };

                foreach (var right in user.Rights)
                {
                    l_user.Rights.Add(new RightEntity() { RightId = right.RightId, Description = right.Description });
                }

                foreach (var project in user.Projects)
                {
                    l_user.Projects.Add(new ProjectEntity() { ProjectId = project.ProjectId, Description = project.Description });
                }

                return l_user;
            }
            return null;
        }