public async Task <ActionResult <ServiceItemResource> > UpdateServiceItem(Guid id, SaveServiceItemResource saveServiceItemResource) { /// validation var validation = new SaveServiceItemResourceValidator(); var validationResult = await validation.ValidateAsync(saveServiceItemResource); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } // si la ServiceItem existe depuis le id var serviceItemUpdate = await _serviceServiceItem.GetServiceItemById(id); if (serviceItemUpdate == null) { return(BadRequest("Service n'existe pas ")); } var serviceItem = _mapperService.Map <SaveServiceItemResource, ServiceItem>(saveServiceItemResource); await _serviceServiceItem.UpdateServiceItem(serviceItemUpdate, serviceItem); var serviceItemUpdateNew = await _serviceServiceItem.GetServiceItemById(id); var serviceItemResourceUpdate = _mapperService.Map <ServiceItem, SaveServiceItemResource>(serviceItemUpdateNew); return(Ok(serviceItemResourceUpdate)); }
public async Task <ActionResult <ServiceItemResource> > CreateServiceItem(SaveServiceItemResource saveServiceItemResource) { // Validation var validation = new SaveServiceItemResourceValidator(); var validationResult = await validation.ValidateAsync(saveServiceItemResource); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } // mappage de SaveServiceItemResource vers ServiceItem var serviceItem = _mapperService.Map <SaveServiceItemResource, ServiceItem>(saveServiceItemResource); // Creation newServiceItem var newServiceItem = await _serviceServiceItem.CreateServiceItem(serviceItem); // mappage de ServiceItem vers ServiceItemResource var serviceItemResource = _mapperService.Map <ServiceItem, ServiceItemResource>(newServiceItem); return(Ok(serviceItemResource)); }