public static void UpdateUser(this User user, UserViewModel userVm)
 {
     user.Username = userVm.Username;
     user.City = userVm.City;
     user.DateOfBirth = userVm.DateOfBirth;
     user.Email = userVm.Email;
     user.RegistrationDate = (user.RegistrationDate == DateTime.MinValue ? DateTime.Now : userVm.RegistrationDate);
 }
        public HttpResponseMessage Register(HttpRequestMessage request, UserViewModel user)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                }
                /*
                else
                {
                    if (_usersRepository.UserExists(user.Email))
                    {
                        ModelState.AddModelError("Invalid user", "Email or Identity Card number already exists");
                        response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                    }
                    else
                    {
                        User newUser = new User();
                        newUser.UpdateUser(user);
                        _usersRepository.Add(newUser);

                        _unitOfWork.Commit();

                        // Update view model
                        user = Mapper.Map<User, UserViewModel>(newUser);
                        response = request.CreateResponse<UserViewModel>(HttpStatusCode.Created, user);
                    }
                }
                */
                return response;
            });
        }
        public HttpResponseMessage Update(HttpRequestMessage request, UserViewModel user)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    User _user = _usersRepository.GetSingle(user.ID);
                    _user.UpdateUser(user);

                    _unitOfWork.Commit();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }

                return response;
            });
        }