public UserAccessRight UpdateUserAccessRight(UserAccessRight userAccessRight)
        {
            var dbContext         = new DataContext();
            var dbUserAccessRight = GetDbUserAccessRight(dbContext, userAccessRight.UserAccessRightId);

            if (dbUserAccessRight != null)
            {
                dbUserAccessRight.DbAccessRight = new AccessRightsRepository().GetDbAccessRight(dbContext, userAccessRight.AccessRight.AccessRightId);
                dbContext.SaveChanges();
            }

            return(new UserAccessRight(dbUserAccessRight));
        }
        public UserAccessRight AddUserAccessRight(UserAccessRight userAccessRight)
        {
            var dbContext         = new DataContext();
            var dbUserAccessRight = new DbUserAccessRight();

            dbUserAccessRight.DbUserAccessRightId = userAccessRight.UserAccessRightId;
            dbUserAccessRight.DbAccessRight       = new AccessRightsRepository().GetDbAccessRight(dbContext, userAccessRight.AccessRight.AccessRightId);
            dbUserAccessRight.DbUser = new UsersRepository().GetDbUser(dbContext, userAccessRight.User.UserId);

            dbUserAccessRight = dbContext.DbUserAccessRights.Add(dbUserAccessRight);
            dbContext.SaveChanges();

            return(new UserAccessRight(dbUserAccessRight));
        }
Пример #3
0
        public IActionResult Put(int id, [FromBody] UserAccessRight formValue)
        {
            //todo access right
            var userAccessRight = _context.UserAccessRights.Find(id);

            if (userAccessRight == null)
            {
                return(NotFound());
            }

            userAccessRight.IsActive       = formValue.IsActive;
            userAccessRight.Role           = formValue.Role;
            userAccessRight.CompanyId      = formValue.CompanyId;
            userAccessRight.DefaultCompany = formValue.DefaultCompany;
            _context.UserAccessRights.Update(userAccessRight);
            _context.SaveChanges();
            return(NoContent());
        }
        public ActionResult <Company> Post([FromBody] Company company)
        {
            company.CreatedAt = DateTime.Now;
            _context.Companies.Add(company);
            _context.SaveChanges();
            var accessright = new UserAccessRight
            {
                CompanyId      = company.Id,
                DefaultCompany = true,
                IsActive       = true,
                Role           = AccessRight.Admin,
                UserId         = CurrentUserId,
                CreatedAt      = DateTime.Now
            };

            _context.Add(accessright);
            _context.SaveChanges();
            return(company);
        }
Пример #5
0
        public async Task <SystemResponse> CreateUserAsync(UserRegister user)
        {
            var newUser = new User
            {
                Civility  = user.Civility,
                FirstName = user.FirstName,
                LastName  = user.LastName
            };

            _context.Users.Add(newUser);
            await _context.SaveChangesAsync();

            var userId = newUser.Id;

            var userCred = new UserCredentials
            {
                UserId   = userId,
                Username = user.Username,
                Password = user.PassWord,
                IsAdmin  = false
            };

            _context.UserCredentials.Add(userCred);
            var canDelete = userCred.IsAdmin;
            var userDefaultAccessRight = new UserAccessRight
            {
                UserId = userId,
                Read   = true,
                Write  = true,
                Delete = canDelete
            };

            _context.UserAccessRights.Add(userDefaultAccessRight);

            await _context.SaveChangesAsync();

            return(SystemResponse.Success);
        }
Пример #6
0
 /// <summary>
 /// Grants the specified user the permissions required to use the specified
 /// datasource.
 /// </summary>
 /// <remarks>
 /// &lt;br/&gt;**Required scope**: Dataset.ReadWrite.All &lt;br/&gt;To set the
 /// permissions scope, see [Register an
 /// app](https://docs.microsoft.com/power-bi/developer/register-app).
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='gatewayId'>
 /// The gateway id
 /// </param>
 /// <param name='datasourceId'>
 /// The datasource id
 /// </param>
 /// <param name='addUserToDatasourceRequest'>
 /// The add user to datasource request
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> AddDatasourceUserAsync(this IGateways operations, string gatewayId, string datasourceId, UserAccessRight addUserToDatasourceRequest, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.AddDatasourceUserWithHttpMessagesAsync(gatewayId, datasourceId, addUserToDatasourceRequest, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #7
0
 /// <summary>
 /// Grants the specified user the permissions required to use the specified
 /// datasource.
 /// </summary>
 /// <remarks>
 /// &lt;br/&gt;**Required scope**: Dataset.ReadWrite.All &lt;br/&gt;To set the
 /// permissions scope, see [Register an
 /// app](https://docs.microsoft.com/power-bi/developer/register-app).
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='gatewayId'>
 /// The gateway id
 /// </param>
 /// <param name='datasourceId'>
 /// The datasource id
 /// </param>
 /// <param name='addUserToDatasourceRequest'>
 /// The add user to datasource request
 /// </param>
 public static object AddDatasourceUser(this IGateways operations, string gatewayId, string datasourceId, UserAccessRight addUserToDatasourceRequest)
 {
     return(operations.AddDatasourceUserAsync(gatewayId, datasourceId, addUserToDatasourceRequest).GetAwaiter().GetResult());
 }
 public void Add(UserAccessRight userAccessRight)
 {
     _repository.AddUserToRight(userAccessRight.UserId, userAccessRight.AccessRightId);
 }
Пример #9
0
        public void UpdateUsersData(UsersDTO userDTO)
        {
            try
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <UsersDTO, UserMaster>();
                    cfg.CreateMap <UserRoleMappingDTO, UserRoleMapping>();
                    cfg.CreateMap <WorkFlowMasterDTO, WorkFlowMaster>();
                    cfg.CreateMap <WorkFlowDetailsDTO, WorkFlowDetail>();
                    cfg.CreateMap <UserAccessRightsDTO, UserAccessRight>();
                });
                IMapper mapper = config.CreateMapper();

                var updateUserDetails = mapper.Map <UsersDTO, UserMaster>(userDTO);

                var workFlowMasterDetails = mapper.Map <List <WorkFlowMasterDTO>, List <WorkFlowMaster> >(userDTO.WorkFlowMasterMappings);

                using (var context = new BIPortalEntities())
                {
                    var EditUserData = context.UserMasters.Where(x => x.UserID == updateUserDetails.UserID).FirstOrDefault();

                    if (EditUserData != null)
                    {
                        EditUserData.EmailID      = updateUserDetails.EmailID;
                        EditUserData.FirstName    = updateUserDetails.FirstName;
                        EditUserData.LastName     = updateUserDetails.LastName;
                        EditUserData.PermissionID = updateUserDetails.PermissionID;
                        EditUserData.Salutation   = updateUserDetails.Salutation;
                        EditUserData.CreatedDate  = DateTime.Now;
                        EditUserData.ModifiedBy   = updateUserDetails.ModifiedBy;
                        EditUserData.ModifiedDate = DateTime.Now;
                        EditUserData.Active       = updateUserDetails.Active;
                        EditUserData.BIObjectType = updateUserDetails.BIObjectType;
                        context.SaveChanges();
                    }


                    // remove existing UserRoleMapping for userid
                    var userRoleMappingRoleExists = context.UserRoleMappings.Where(x => x.UserID == updateUserDetails.UserID);
                    if (userRoleMappingRoleExists != null)
                    {
                        context.UserRoleMappings.RemoveRange(userRoleMappingRoleExists);
                        context.SaveChanges();
                    }

                    // Insert UserRoleMapping
                    foreach (var d in userDTO.SelectedRolesValues)
                    {
                        var userrolemapping = new UserRoleMapping
                        {
                            //RoleID = 1, //should come from UI
                            RoleID      = d,
                            CreatedDate = DateTime.Now,
                            //CreatedBy = "Selva",
                            CreatedBy = updateUserDetails.CreatedBy,
                            Active    = true
                        };
                        EditUserData.UserRoleMappings.Add(userrolemapping);
                    }
                    context.SaveChanges();

                    // remove existing UserAccessRights for userid
                    var userUserAccessRightsMappingUserExists = context.UserAccessRights.Where(x => x.UserID == updateUserDetails.UserID);
                    if (userUserAccessRightsMappingUserExists != null)
                    {
                        context.UserAccessRights.RemoveRange(userUserAccessRightsMappingUserExists);
                        context.SaveChanges();
                    }

                    //Insert UserAccessRights
                    foreach (var e in userDTO.UserAccessRightsMappings)
                    {
                        var userRightsAccessMapping = new UserAccessRight
                        {
                            UserID        = updateUserDetails.UserID,
                            WorkspaceID   = e.WorkspaceID,
                            WorkspaceName = e.WorkspaceName,
                            ReportID      = e.ReportID,
                            ReportName    = e.ReportName,
                            CreatedDate   = DateTime.Now,
                            CreatedBy     = e.CreatedBy,
                            ModifiedDate  = DateTime.Now,
                            ModifiedBy    = e.ModifiedBy,
                            Active        = e.Active
                        };
                        EditUserData.UserAccessRights.Add(userRightsAccessMapping);
                    }
                    context.SaveChanges();

                    // save only active users
                    if (userDTO.Active)
                    {
                        context.WorkFlowMasters.AddRange(workFlowMasterDetails);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }
Пример #10
0
        public void SaveUsersData(UsersDTO userDTO)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <UsersDTO, UserMaster>();
                cfg.CreateMap <UserRoleMappingDTO, UserRoleMapping>();
                cfg.CreateMap <WorkFlowMasterDTO, WorkFlowMaster>();
                cfg.CreateMap <WorkFlowDetailsDTO, WorkFlowDetail>();
                cfg.CreateMap <UserAccessRightsDTO, UserAccessRight>();
            });
            IMapper mapper = config.CreateMapper();

            var SaveUserDetails = mapper.Map <UsersDTO, UserMaster>(userDTO);

            var workFlowMasterDetails = mapper.Map <List <WorkFlowMasterDTO>, List <WorkFlowMaster> >(userDTO.WorkFlowMasterMappings);

            using (var context = new BIPortalEntities())
            {
                var saveUserMaster = new UserMaster
                {
                    Salutation   = SaveUserDetails.Salutation,
                    FirstName    = SaveUserDetails.FirstName,
                    LastName     = SaveUserDetails.LastName,
                    EmailID      = SaveUserDetails.EmailID,
                    PermissionID = SaveUserDetails.PermissionID,
                    CreatedDate  = DateTime.Now,
                    CreatedBy    = SaveUserDetails.CreatedBy,
                    ModifiedDate = DateTime.Now,
                    Active       = SaveUserDetails.Active,
                    BIObjectType = SaveUserDetails.BIObjectType
                };

                // Insert UserRoleMapping
                foreach (var d in userDTO.SelectedRolesValues)
                {
                    var userrolemapping = new UserRoleMapping
                    {
                        //RoleID = 1, //should come from UI
                        RoleID      = d,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = SaveUserDetails.CreatedBy,
                        Active      = true
                    };
                    saveUserMaster.UserRoleMappings.Add(userrolemapping);
                }


                // Insert UserAcessRights
                foreach (var e in userDTO.UserAccessRightsMappings)
                {
                    var userRightsAccessMapping = new UserAccessRight
                    {
                        UserID        = SaveUserDetails.UserID,
                        WorkspaceID   = e.WorkspaceID,
                        WorkspaceName = e.WorkspaceName,
                        ReportID      = e.ReportID,
                        ReportName    = e.ReportName,
                        //CreatedDate = e.CreatedDate,
                        CreatedDate = DateTime.Now,
                        CreatedBy   = e.CreatedBy,
                        Active      = e.Active
                    };
                    saveUserMaster.UserAccessRights.Add(userRightsAccessMapping);
                }
                context.UserMasters.Add(saveUserMaster);
                context.SaveChanges();

                context.WorkFlowMasters.AddRange(workFlowMasterDetails);
                context.SaveChanges();
            }
        }
        private async void saveButton_Click(object sender, RoutedEventArgs e)
        {
            if (firstNameTextBox.Text.Length > 0 && lastNameTextBox.Text.Length > 0 && genderComboBox.SelectedIndex >= 0)
            {
                if (userIdTextBox.Text.Length > 0 && passwordTextBox.Password.Length > 0 && confirmPasswordTextBox.Password.Length > 0)
                {
                    if (passwordTextBox.Password == confirmPasswordTextBox.Password)
                    {
                        if (selectAccessRightsControl.SelectedAccessRights.Count > 0)
                        {
                            progressBar.Visibility = Visibility.Visible;
                            cancelButton.IsEnabled = false;
                            saveButton.IsEnabled   = false;

                            var selectedGenderView = genderComboBox.SelectedValue as GenderView;
                            var selectedGender     = selectedGenderView.gender;

                            var client = await BacklogAPIClientBuilder.GetBackLogAPIClientAsync();

                            User = new User {
                                FirstName = firstNameTextBox.Text, LastName = lastNameTextBox.Text, Gender = selectedGender, UserId = Guid.NewGuid()
                            };

                            try
                            {
                                // Add user
                                User = await client.AddUserAsync(User);

                                // Add Login
                                var userLogin = new UserLogin {
                                    UserLoginId = Guid.NewGuid(), UserId = userIdTextBox.Text, PasswordHash = passwordTextBox.Password, User = User
                                };
                                userLogin = await client.AddUserLoginAsync(userLogin);

                                // Add Access Rights
                                foreach (var selectedAccessRight in selectAccessRightsControl.SelectedAccessRights)
                                {
                                    var userAccessRight = new UserAccessRight {
                                        UserAccessRightId = Guid.NewGuid(), AccessRight = selectedAccessRight, User = User
                                    };
                                    userAccessRight = await client.AddUserAccessRightAsync(userAccessRight);
                                }


                                UserWasAdded = true;
                                Close();
                                MessageBox.Show("User was added.");
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }

                            progressBar.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            MessageBox.Show("You have not selected any Access Rights for this user.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("The Password and Confirm Password fields do not match.");
                    }
                }
                else
                {
                    MessageBox.Show("One or more fields in Login Info section are empty.");
                }
            }
            else
            {
                MessageBox.Show("One or more fields in Personal Info section are empty.");
            }
        }
Пример #12
0
 public ActionResult <UserAccessRight> Post([FromBody] UserAccessRight userAccessRight)
 {
     _context.UserAccessRights.Add(userAccessRight);
     _context.SaveChanges();
     return(userAccessRight);
 }
Пример #13
0
 public UserAccessRight UpdateUserAccessRight(UserAccessRight userAccessRight)
 {
     return(new UserAccessRightsRepository().UpdateUserAccessRight(userAccessRight));
 }
Пример #14
0
 public UserAccessRight AddUserAccessRight(UserAccessRight userAccessRight)
 {
     return(new UserAccessRightsRepository().AddUserAccessRight(userAccessRight));
 }