Пример #1
0
        internal static String Save(DB.SEC_UserRole entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySecurityContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySecurityContext.SEC_UserRole.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Пример #2
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }

                    DB.SEC_User            secUser       = (DB.SEC_User)BindingSource.DataSource;
                    DB.SYS_Person          sys_person    = (DB.SYS_Person)BindingSourcePerson.DataSource;
                    List <DB.SEC_UserRole> current       = secUser.SEC_UserRole.Select(n => n as DB.SEC_UserRole).ToList();
                    List <DB.SEC_Role>     selectedroles = lstRoles.CheckedItems.Cast <DB.SEC_Role>().ToList();
                    // Get all the roles that have been added to the user.
                    List <Int64> roleidsrequired = selectedroles.Where(n => !current.Select(m => m.RoleId).Contains(n.Id)).Select(n => n.Id).ToList();
                    foreach (Int64 id in roleidsrequired)
                    {
                        DB.SEC_UserRole userrole = BL.SEC.SEC_UserRole.New;
                        userrole.UserId = secUser.Id;
                        userrole.RoleId = id;
                        secUser.SEC_UserRole.Add(userrole);
                    }
                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            BL.EntityController.SaveSYS_Person(sys_person, DataContext);
                            DataContext.SaveChangesEntitySystemContext();
                            secUser.PersonId = sys_person.Id;
                            BL.EntityController.SaveSEC_User(secUser, DataContext);
                            if (RollHasChanged)
                            {
                                // Remove the roles that are on the user and not in the checked list.
                                List <DB.SEC_UserRole> roleidsdeleted = current.Where(n => !selectedroles.Select(m => m.Id).Contains(n.RoleId)).ToList();

                                foreach (DB.SEC_UserRole ur in roleidsdeleted)
                                {
                                    BL.SEC.SEC_UserRole.DeleteUserRole(ur, DataContext);
                                }

                                //TODO : Remove this when log system is added
                                //BL.SEC.SEC_User.UpdateRoleModifiedFlags(secUser, DataContext);
                            }
                            DataContext.SaveChangesEntitySecurityContext();
                            DataContext.SaveChangesEntitySystemContext();
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntitySecurityContext.AcceptAllChanges();
                        DataContext.EntitySystemContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntitySecurityContext.RejectChanges();
                        DataContext.EntitySystemContext.RejectChanges();
                        HasErrors = true;
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Пример #3
0
 public static void DeleteUserRole(DB.SEC_UserRole sec_userrole, DataContext dataContext)
 {
     dataContext.EntitySecurityContext.SEC_UserRole.Remove(sec_userrole);
     //dataContext.EntityContext.SaveChanges();
 }