public HttpResponseMessage Register(HttpRequestMessage request, ClientModel _clientModel)
        {
            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
                {
                    Client newClient = new Client();
                    newClient.AsClient(_clientModel);

                    _clientRepository.Add(newClient);
                    _unitOfWork.Commit();

                    _clientModel = Mapper.Map<Client, ClientModel>(newClient);
                    response = request.CreateResponse<ClientModel>(HttpStatusCode.Created, _clientModel);
                }

                return response;
            });
        }
 public static void AsClient(this Client client, ClientModel clientModel)
 {
     client.FirstName = clientModel.FirstName;
     client.LastName = clientModel.LastName;
     client.Email = clientModel.Email;
     client.Mobile = clientModel.Mobile;
     client.UniqueKey = (clientModel.UniqueKey == null || clientModel.UniqueKey == Guid.Empty)
         ? Guid.NewGuid() : clientModel.UniqueKey;
 }
        public HttpResponseMessage Update(HttpRequestMessage request, ClientModel _clientModel)
        {
            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
                {
                    Client client = _clientRepository.GetSingle(_clientModel.ID);
                    client.AsClient(_clientModel);

                    _unitOfWork.Commit();

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

                return response;
            });
        }