public async Task <IActionResult> Update(string id, RessourceTypeViewModel ressourceTypeIn) { if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); } var ressourceTypeToUpdate = await _ressourceTypeService.Get(id); if (ressourceTypeToUpdate == null) { return(NotFound()); } try { ressourceTypeToUpdate.Type = ressourceTypeIn.Type; ressourceTypeToUpdate.Name = ressourceTypeIn.Name; ressourceTypeToUpdate.Description = ressourceTypeIn.Description; await _ressourceTypeService.Update(ressourceTypeToUpdate); } catch (RessourceTypeRepositoryException ex) { ModelState.AddModelError(ex.Field, ex.Message); return(BadRequest(new ValidationProblemDetails(ModelState))); } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } return(CreatedAtRoute("GetRessourceType", new { id = ressourceTypeIn.Id.ToString() }, ressourceTypeIn)); }
public async Task <ActionResult <RessourceType> > Create(RessourceTypeViewModel ressourceTypeIn) { if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); } var ressourceType = new RessourceType { Description = ressourceTypeIn.Description, Name = ressourceTypeIn.Name, Type = ressourceTypeIn.Type }; try { await _ressourceTypeService.Create(ressourceType); } catch (RessourceTypeRepositoryException ex) { ModelState.AddModelError(ex.Field, ex.Message); return(BadRequest(new ValidationProblemDetails(ModelState))); } catch (Exception ex) { return(StatusCode(500, "Internal server error")); } return(CreatedAtRoute("GetRessourceType", new { id = ressourceType.Id.ToString() }, ressourceType)); }