Exemplo n.º 1
0
        public ResponseViewModel <AssignPermissionResponseViewModel> AssignPermissionToRole(AssignPermissionRequestViewModel inputModel)
        {
            ResponseViewModel <AssignPermissionResponseViewModel> response = new ResponseViewModel <AssignPermissionResponseViewModel>();

            try
            {
                List <RolePermission> lstRolePermission = new List <RolePermission>();

                for (int i = 0; i < inputModel.lstPermission.Count; i++)
                {
                    RolePermission objRolePermission = new RolePermission
                    {
                        PermissionId = inputModel.lstPermission[i].permissionid,
                        RoleId       = inputModel.lstPermission[i].roleid,
                        CreatedBy    = inputModel.createdby,
                        UpdatedBy    = inputModel.updatedby,
                        CreatedOn    = DateTime.UtcNow,
                        UpdatedOn    = DateTime.UtcNow,
                        IsDeleted    = false
                    };
                    lstRolePermission.Add(objRolePermission);
                }

                bool result = _permissionRepository.AssignPermissionToRole(inputModel.roleid, lstRolePermission);
                if (result)
                {
                    response.Status  = true;
                    response.Message = _errorMessageService.GetErrorMessagesData("135");
                    response.Result  = null;
                }
                else
                {
                    response.Status  = false;
                    response.Message = _errorMessageService.GetErrorMessagesData("136");
                    response.Result  = null;
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    _loggerService.LogError(1, "## [PermissionService][AssignPermissionToRole] innerexception :" + ex.InnerException.ToString());

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

                response.Status     = false;
                response.Message    = _errorMessageService.GetErrorMessagesData("501");
                response.StatusCode = (int)HttpStatusCode.BadRequest;
            }

            return(response);
        }