public IHttpActionResult GetNumberOfEmployees()
        {
            var employeeList      = db.Users.ToList().Select(x => ViewModelMapper.ToViewModelUsers(x)).ToList();
            var numberOfEmployees = employeeList.Count;

            return(Ok(numberOfEmployees));
        }
示例#2
0
        //Get All Users
        public List <UserViewModel> GetUsers()
        {
            List <User> users = db.Users.ToList();

            List <UserViewModel> viewModels = new List <UserViewModel>();

            foreach (User u in users)
            {
                UserViewModel vm = ViewModelMapper.ToViewModelUsers(u);
                viewModels.Add(vm);
            }

            return(viewModels);
        }
示例#3
0
        public IHttpActionResult PostUser(UserViewModel userViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            User user = new User {
                UserName = userViewModel.UserName, Email = userViewModel.Email, FirstName = userViewModel.FirstName,
                LastName = userViewModel.LastName, JobTypeId = userViewModel.JobTypeId
            };

            var result = UserManager.CreateAsync(user).Result;

            return(CreatedAtRoute("DefaultApi", new { id = user.Id }, ViewModelMapper.ToViewModelUsers(user)));
        }