Exemplo n.º 1
0
        public async Task <IActionResult> AddOrUpdatePermission([FromBody] ChangePermissionModel model)
        {
            #region Validation

            if (!ModelState.IsValid)
            {
                return(BadRequest(ErrorResponse.Create(ModelState)));
            }

            if (model.Role == Role.Unknown)
            {
                return(BadRequest(ErrorResponse.Create("Role is not defined")));
            }

            #endregion

            try
            {
                var permissions = await _service.AddOrUpdatePermissionAsync(model.FileId, model.EmailAddress, model.Role);

                return(Ok(permissions));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync("GoogleDriveController", nameof(AddOrUpdatePermission), string.Empty, ex);

                return(StatusCode(500, ErrorResponse.Create(ex.Message)));
            }
        }