Beispiel #1
0
        public async Task <ActionResult <BreedResponse> > GetByName([FromRoute] string breedName)
        {
            BreedResult result = await _agroBarnSupervisor.GetBreedByNameAsync(breedName);

            if (!result.Success)
            {
                return(ResponseErrorCode(result));
            }

            BreedResponse breed = _mapper.Map <BreedResponse>(result);

            return(Ok(breed));
        }
Beispiel #2
0
        public async Task <ActionResult <BreedResponse> > Update([FromRoute] int breedId, [FromBody] BreedRequest breed)
        {
            int         userId = int.Parse(HttpContext.GetUserId());
            BreedResult result = await _agroBarnSupervisor.UpdateBreedAsync(breed, breedId, userId);

            if (!result.Success)
            {
                return(ResponseErrorCode(result));
            }

            BreedResponse response = _mapper.Map <BreedResponse>(result);

            return(Ok(response));
        }
Beispiel #3
0
        public async Task <ActionResult <BreedResponse> > Post([FromBody] BreedRequest newBreed)
        {
            int         userId = int.Parse(HttpContext.GetUserId());
            BreedResult result = await _agroBarnSupervisor.AddBreedAsync(newBreed, userId);

            if (!result.Success)
            {
                return(ResponseErrorCode(result));
            }

            BreedResponse breed       = _mapper.Map <BreedResponse>(result);
            var           baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var           locationUri = baseUrl + "/" + ApiRoutes.Breeds.GetById.Replace("{breedId}", breed.Id.ToString());

            return(Created(locationUri, breed));
        }