public async Task <ActionResult <RequestResource> > UpdateRequest(int id, [FromBody] SaveRequestResource saveRequestResource)
        {
            var validator        = new SaveRequestResourceValidator();
            var validationResult = await validator.ValidateAsync(saveRequestResource);

            var requestIsInvalid = id == 0 || !validationResult.IsValid;

            if (requestIsInvalid)
            {
                return(BadRequest(validationResult.Errors)); // this needs refining, but for demo it is ok
            }
            var requestToBeUpdate = await _requestService.GetRequestById(id);

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

            var request = _mapper.Map <SaveRequestResource, Request>(saveRequestResource);

            await _requestService.UpdateRequest(requestToBeUpdate, request);

            var updatedRequest = await _requestService.GetRequestById(id);

            var updatedRequestResource = _mapper.Map <Request, RequestResource>(updatedRequest);

            return(Ok(updatedRequestResource));
        }
        public async Task <IActionResult> PutAsync(int userId, int requestId, [FromBody] SaveRequestResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var request = mapper.Map <SaveRequestResource, Domain.Models.Request>(resource);
            var result  = await requestService.UpdateAsync(userId, requestId, request);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var requestResource = mapper.Map <Domain.Models.Request, RequestResource>(result.Resource);

            return(Ok(requestResource));
        }
        public async Task <ActionResult <RequestResource> > CreateRequest([FromBody] SaveRequestResource saveRequestResource)
        {
            var validator        = new SaveRequestResourceValidator();
            var validationResult = await validator.ValidateAsync(saveRequestResource);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors)); // this needs refining, but for demo it is ok
            }
            var requestToCreate = _mapper.Map <SaveRequestResource, Request>(saveRequestResource);

            var newRequest = await _requestService.CreateRequest(requestToCreate);

            var request = await _requestService.GetRequestById(newRequest.Id);

            var requestResource = _mapper.Map <Request, RequestResource>(request);

            return(Ok(requestResource));
        }
        public async Task <ActionResult> RegisterRequestByPersonId(int personId, int petId, int providerId, int productTypeId, int productId, [FromBody] SaveRequestResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }


            var request = _mapper.Map <SaveRequestResource, PersonRequest>(resource);
            var result  = await _requestService.SaveByCustomerIdAsync(personId, providerId, productTypeId, productId, petId, request);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var requestResource = _mapper.Map <PersonRequest, RequestResource>(result.Request);

            return(Ok(requestResource));
        }