Exemple #1
0
        //<remarks>
        // Creates a new pet in the store.  Duplicates are allowed
        //</remarks>
        //<returns>
        // pet response
        //</returns>
        //<param name="pet">Pet to add to the store</param>
        public async Task <APIResponse <Pet> > addPetAsync(PetInput pet)
        {
            {
                var response = await httpClient.PostAsync(new Uri(url + "/pets", UriKind.Absolute), new SwaggerHTTPClientOptions(TimeSpan.FromSeconds(30)), new StringContent(JsonConvert.SerializeObject(pet)));

                if (response == null)
                {
                    return(new APIResponse <Pet>(false));
                }

                switch ((int)response.StatusCode)
                {
                case 200:
                {
                    var data = JsonConvert.DeserializeObject <Pet>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse <Pet>(data, response.StatusCode));
                }

                case 200:
                {
                    var data = JsonConvert.DeserializeObject <Pet>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse <Pet>(data, response.StatusCode));
                }

                default:
                {
                    return(new APIResponse <Pet>(response.StatusCode));
                }
                }
            }
        }
Exemple #2
0
        public async Task <IActionResult> Update([FromRoute] int id, [FromBody] PetInput petInput)
        {
            var pet = await petBusiness.Update(id, petInput);

            if (pet == null)
            {
                return(NotFound());
            }

            return(Accepted(nameof(GetPorId), pet));
        }
Exemple #3
0
        public async Task <IActionResult> PostPet([FromBody] PetInput petInput)
        {
            var pet = await petBusiness.Inserir(petInput);

            if (pet == null)
            {
                return(BadRequest());
            }

            return(Created(nameof(GetPorId), pet));
        }
Exemple #4
0
        public async Task <Pet> Update(int id, PetInput petInput)
        {
            var petExiste = await petRepository.SelecionarPorId(id);

            if (petExiste == null)
            {
                return(null);
            }

            Pet newPet = new Pet(petInput.Nome, petInput.Idade, petInput.Descricao, petInput.NomeTutor, petInput.Vacinado, petInput.Castrado, petInput.Match, petInput.Imagem, petInput.Bairro, petInput.Cidade, petInput.Estado);

            await petRepository.Update(id, newPet);

            return(await petRepository.SelecionarPorId(id));
        }
Exemple #5
0
        public async Task <Pet> Inserir(PetInput petInput)
        {
            Pet newPet = new Pet(petInput.Nome, petInput.Idade, petInput.Descricao, petInput.NomeTutor, petInput.Vacinado, petInput.Castrado, petInput.Match, petInput.Imagem, petInput.Bairro, petInput.Cidade, petInput.Estado);

            return(await petRepository.Inserir(newPet));
        }