コード例 #1
0
        public IActionResult Post([FromBody] AssignPermissionRequestViewModel inputModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new ApiBadRequestResponse(ModelState)));
                }

                var currentUser = HttpContext.User;
                if (currentUser.HasClaim(c => c.Type == ClaimTypes.Email))
                {
                    string email = currentUser.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value;
                    inputModel.createdby = email;
                    inputModel.updatedby = email;
                }

                ResponseViewModel <AssignPermissionResponseViewModel> response = _permissionService.AssignPermissionToRole(inputModel);

                if (response.Status)
                {
                    return(Ok(new ApiOkResponse((int)HttpStatusCode.OK, true, response.Message, response.Result)));
                }
                else
                {
                    return(Ok(new ApiBadResponse(response.StatusCode, response.Status, response.Message, "", response.Errors)));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    _loggerService.LogError(1, "## [PermissionController][AssignPermissionToRole] innerexception :" + ex.InnerException.ToString());

                    if (ex.InnerException.Message != null)
                    {
                        _loggerService.LogError(1, "## [PermissionController][AssignPermissionToRole] innerexception message :" + ex.InnerException.Message.ToString());
                    }
                }
                else
                {
                    _loggerService.LogError(1, "## [PermissionController][AssignPermissionToRole] exception :" + ex.Message.ToString());
                }

                var Message = _errorMessageService.GetErrorMessagesData("501");
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ApiInternalServerErrorResponse((int)HttpStatusCode.InternalServerError, false, Message, "")));
            }
        }