public async Task <ActionResult <PermissionTypeDto> > UpdateArtist(int id, [FromBody] SavePermissionTypeDto dto) { var validator = new SavePermissionTypeDtoValidator(); var validationResult = await validator.ValidateAsync(dto); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var permissionTobeEdited = await _service.GetById(id); if (permissionTobeEdited == null) { return(NotFound()); } var permissionType = _mapper.Map <SavePermissionTypeDto, PermissionType>(dto); await _service.Update(permissionTobeEdited, permissionType); var editedPermissionType = await _service.GetById(id); var editedPermissionTypeDto = _mapper.Map <PermissionType, PermissionTypeDto>(editedPermissionType); return(Ok(editedPermissionTypeDto)); }
public async Task <ActionResult <PermissionTypeDto> > Create([FromBody] SavePermissionTypeDto dto) { var validator = new SavePermissionTypeDtoValidator(); var validationResult = await validator.ValidateAsync(dto); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var permissionTypeToCreate = _mapper.Map <SavePermissionTypeDto, PermissionType>(dto); var createdPermissionType = await _service.Create(permissionTypeToCreate); var permissionType = await _service.GetById(createdPermissionType.Id); var permissionTypeDto = _mapper.Map <PermissionType, PermissionTypeDto>(permissionType); return(Ok(permissionTypeDto)); }