Ejemplo n.º 1
0
        public async Task <IActionResult> CreateService([FromBody] SaveServicesResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            resource.ServiceProviderId = await GetServiceProviderId();

            var service = _mapper.Map <SaveServicesResource, Service>(resource);

            _repository.Add(service);

            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map(service, resource);

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Update(int id, [FromBody] SaveServicesResource resource)
        {
            IActionResult result;
            var           serviceDetails = await _repository.GetServiceAsync(id);

            if (serviceDetails != null)
            {
                var mapperResult = _mapper.Map <SaveServicesResource, Service>(resource, serviceDetails);
                mapperResult.ServiceProviderId = await GetServiceProviderId();

                await _unitOfWork.CompleteAsync();

                result = Ok(mapperResult);
            }
            else
            {
                result = NotFound();
            }

            return(result);
        }