Пример #1
0
        public async Task <IActionResult> AttachToOrganizationRightAsync([FromBody] AttachDetachRightRequest attachDetachRightRequest)
        {
            var currentUserId = GetCurrentUserId();

            try
            {
                await organizationManager.AttachToRightAsync(attachDetachRightRequest, currentUserId);

                return(Ok());
            }
            catch (ArgumentNullException ane)
            {
                logger.LogDebug(ane.Message + "\n" + ane.StackTrace);
                return(NotFound("Can't find organization, user or right"));
            }
            catch (ArgumentException ae)
            {
                logger.LogDebug(ae.Message + "\n" + ae.StackTrace);
                logger.LogDebug($"Can't attacth user {attachDetachRightRequest.UserId} to right {attachDetachRightRequest.Right}");
                return(BadRequest("Can't attach to this right"));
            }
            catch (MethodAccessException mae)
            {
                logger.LogDebug(mae.Message + "\n" + mae.StackTrace);
                logger.LogDebug($"User {currentUserId} has no rights to edit rights in organization {attachDetachRightRequest.OrganizationId}");
                return(Forbid(JwtBearerDefaults.AuthenticationScheme, CookieAuthenticationDefaults.AuthenticationScheme));
            }
            catch (MemberAccessException mae)
            {
                logger.LogDebug(mae.Message + "\n" + mae.StackTrace);
                logger.LogDebug($"User {attachDetachRightRequest.UserId} already has right {attachDetachRightRequest.Right} in organization {attachDetachRightRequest.OrganizationId}");
                return(BadRequest("User already has this right in organization"));
            }
            catch (Exception ex)
            {
                logger.LogDebug(ex.Message + "\n" + ex.StackTrace);
                return(StatusCode(500));
            }
        }