Example #1
0
        internal static String Save(DB.SEC_RoleAccess entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySecurityContext.SEC_RoleAccess.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Example #2
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }
                    //Get all the selected nodes
                    List <DB.SEC_Access>     accesses = GetAllSelectedAccess();
                    List <DB.SEC_RoleAccess> current  = secRole.SEC_RoleAccess.ToList();
                    // Add the accesses that are in the chekced nodes and not yet in the role
                    List <Int64> accessidsrequired = accesses.Where(n => !current.Select(m => m.AccessId).Contains(n.Id)).Select(n => n.Id).ToList();
                    foreach (Int64 id in accessidsrequired)
                    {
                        DB.SEC_RoleAccess roleacc = BL.SEC.SEC_RoleAccess.New;
                        roleacc.AccessId = id;
                        roleacc.RoleId   = secRole.Id;
                        secRole.SEC_RoleAccess.Add(roleacc);
                    }
                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            BL.EntityController.SaveSEC_Role(secRole, DataContext);
                            DataContext.EntitySecurityContext.SaveChanges();

                            if (AccessHasChanged)
                            {
                                // Remove the accesses that are on the role and not in the checked nodes.
                                List <DB.SEC_RoleAccess> accessidsdeleted = current.Where(n => !accesses.Select(m => m.Id).Contains(n.AccessId)).ToList();

                                foreach (DB.SEC_RoleAccess ra in accessidsdeleted)
                                {
                                    BL.SEC.SEC_RoleAccess.DeleteRoleAccess(ra, DataContext);
                                }
                                //TODO : Remove this when log system is added
                                BL.SEC.SEC_Role.UpdateAccessModifiedFlags(secRole);
                            }
                            DataContext.EntitySecurityContext.SaveChanges();
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntitySecurityContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntitySecurityContext.RejectChanges();
                        HasErrors = true;
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                HasErrors        = true;
                CurrentException = ex;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Example #3
0
 public static void DeleteRoleAccess(DB.SEC_RoleAccess sec_roleaccess, DataContext dataContext)
 {
     dataContext.EntitySecurityContext.SEC_RoleAccess.Remove(sec_roleaccess);
 }