Esempio n. 1
0
        public PersonDto PutPerson(int id, PersonRequestModel requestModel)
        {
            var person = Mapper.Map<PersonRequestModel, Person>(requestModel);
            person.Id = id;
            var personResult = this.peopleService.UpdateUser(person);
            if (!personResult.IsOK)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }

            return Mapper.Map<Person, PersonDto>(personResult.Result);
        }
Esempio n. 2
0
        public HttpResponseMessage PostPerson(PersonRequestModel requestModel)
        {
            var person = Mapper.Map<PersonRequestModel, Person>(requestModel);
            var personResult = this.peopleService.AddNewUser(person);
            if (!personResult.IsOK)
            {
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }

            var personDto = Mapper.Map<Person, PersonDto>(personResult.Result);
            return Request.CreateResponse(HttpStatusCode.Created, personDto);
        }
Esempio n. 3
0
        public async Task<ActionResult> UserRole() {

            var model = new PersonRequestModel {
                Name = "Updated Demo User 1",
                Email = "*****@*****.**",
                BirthYear = 1982
            };

            HttpApiResponseMessage<PersonDto> apiResponse = 
                await _peopleClient.UpdatePersonAsync(8, model);

            return View("~/Views/HardCoded/UserRole.cshtml", apiResponse.Model);
        }
Esempio n. 4
0
        private IEnumerable<Task<HttpResponseMessage>> GetRequests(HttpClient httpClient)
        {
            for (int i = 0; i < 5; i++)
            {

                var requestMessage = new HttpRequestMessage(HttpMethod.Post, "https://*****:*****@email.com", i),
                    BirthYear = 1982
                };

                requestMessage.Content = new ObjectContent<PersonRequestModel>(model, new JsonMediaTypeFormatter());

                yield return httpClient.SendAsync(requestMessage);
            }
        }
Esempio n. 5
0
        public async Task<ActionResult> UserRole()
        {
            // apikeyforuser
            // user
            // password

            var client = new HttpClient();

            var requestMessage = new HttpRequestMessage(HttpMethod.Put, "https://*****:*****@email.com",
                BirthYear = 1982
            };

            requestMessage.Content = new ObjectContent<PersonRequestModel>(model, new JsonMediaTypeFormatter());
            
            var response = await client.SendAsync(requestMessage);
            var content = await response.Content.ReadAsAsync<PersonDto>();
            
            return View(content);
        }
Esempio n. 6
0
 public Task<HttpApiResponseMessage<PersonDto>> UpdatePersonAsync(int personId, PersonRequestModel model)
 {
     // https://localhost:44307/v1/people
     var requestUri = string.Format("{0}/v1/people/{1}", _baseUri, personId);
     return _httpClient.PutAsJsonAsync(requestUri, model).GetHttpApiResponseAsync<PersonDto>();
 }
Esempio n. 7
0
 public Task<HttpApiResponseMessage<PersonDto>> AddPersonAsync(PersonRequestModel model)
 {
     // https://localhost:44307/v1/people
     var requestUri = string.Format("{0}/v1/people", _baseUri);
     return _httpClient.PostAsJsonAsync(requestUri, model).GetHttpApiResponseAsync<PersonDto>();
 }