public IActionResult Post([FromBody] PermissionInsertDto permission) { if (ModelState.IsValid) { try { var domainPermission = permission.ToDomain(); var created = _permissionRepository.Insert(domainPermission); var createdDto = created.ToDto(); return(CreatedAtAction(nameof(Get), new { id = created.Id }, createdDto)); } catch (Exception e) { _logger.LogError($"An error occured while creating permission with given parameters" + $" userId: {permission.UserId}, objectId = {permission.ObjectId} with exception: {e}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } } else { return(BadRequest(ModelState)); } }
public static Permission ToDomain(this PermissionInsertDto dto) { return(new Permission { PermissionSubject = dto.PermissionSubject, PermissionLevel = dto.PermissionLevel, UserId = dto.UserId, ObjectId = dto.ObjectId }); }