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

            return("Success");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads and opens the next User record. The current record is not saved.
        /// </summary>
        /// <remarks>Created: Theo Crous 23/07/2012</remarks>
        protected override void OnNextRecord()
        {
            try
            {
                base.OnNextRecord();

                DB.SEC_User secUser = BL.SEC.SEC_User.GetNextItem((DB.SEC_User)BindingSource.DataSource, DataContext);
                if (secUser != null)
                {
                    BindingSource.DataSource = secUser;
                    BindData();
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 3
0
 public static DB.SEC_User GetPreviousItem(DB.SEC_User sec_user, DataContext dataContext)
 {
     return(dataContext.EntitySecurityContext.SEC_User.OrderByDescending(o => o.DisplayName).FirstOrDefault(n => n.DisplayName.CompareTo(sec_user.DisplayName) < 0 && n.DisplayName.CompareTo(sec_user.DisplayName) != 0));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Attempt to sign into the system with the provided username and password. Note that a database connection must already have been established at this point.
        /// </summary>
        /// <param name="Username">The case insensitive username.</param>
        /// <param name="Password">The case insensitive password.</param>
        /// <returns>Returns true if the user details are correct and could be retrieved, otherwise returns false.</returns>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        public static bool Signin(String Username, String Password)
        {
            try
            {
                //CompleteDataLayer.User user = CompleteDataLayer.UserDataProvider.Instance.Authenticate(Username, Password);


                DB.SEC_User user = BL.SEC.SEC_User.Authenticate(Username, EncodePassword(Password));


                if (user != null)
                {
                    // User provided correct credentials
                    ApplicationDataContext.Instance.LoggedInUser                = user;
                    ApplicationDataContext.Instance.LoggedInUser.Person         = ApplicationDataContext.Instance.SystemEntityContext.SYS_Person.FirstOrDefault(n => n.Id == ApplicationDataContext.Instance.LoggedInUser.PersonId);
                    ApplicationDataContext.Instance.LoggedInUser.DefaultPrinter = ApplicationDataContext.Instance.SystemEntityContext.SYS_Printer.FirstOrDefault(n => n.Id == ApplicationDataContext.Instance.LoggedInUser.DefaultPrinterId);
                    ApplicationDataContext.Instance.LoggedInUser.DefaultSite    = ApplicationDataContext.Instance.SystemEntityContext.SYS_Site.Include("SYS_Entity").FirstOrDefault(n => n.EntityId == ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId);
                    //Console.WriteLine(ApplicationDataContext.Instance.LoggedInUser.DefaultSite.SYS_Entity.Id);
                    int PortStartIndex = 1000;
                    int PortEndIndex   = 2000;
                    System.Net.NetworkInformation.IPGlobalProperties properties = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
                    IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();

                    List <int> usedPorts  = tcpEndPoints.Select(p => p.Port).ToList <int>();
                    int        unusedPort = 0;

                    for (int port = PortStartIndex; port < PortEndIndex; port++)
                    {
                        if (!usedPorts.Contains(port))
                        {
                            unusedPort = port;
                            break;
                        }
                    }

                    // Update Last Login Details
                    user.LastDate = DateTime.Now;
                    //user.LastLocation = String.Format("Machine: {0};OS: {1}; User:{2}; IP: {3}", Environment.MachineName, Environment.OSVersion, Environment.UserName, System.Net.Dns.GetHostAddresses(Environment.MachineName).Where(n => !n.IsIPv6LinkLocal && !n.IsIPv6Multicast && !n.IsIPv6SiteLocal && !n.IsIPv6Teredo).FirstOrDefault().ToString());
                    user.LastLocation = String.Format("Machine: {0};OS: {1}; User:{2}; IP: {3};Open Port: {4}", Environment.MachineName, Environment.OSVersion, Environment.UserName, System.Net.Dns.GetHostAddresses(Environment.MachineName).Where(n => !n.IsIPv6LinkLocal && !n.IsIPv6Multicast && !n.IsIPv6SiteLocal && n.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault().ToString(), unusedPort);
                    //IF this is null you are not loggin in from CDS.Desktop
                    if (Assembly.GetEntryAssembly() == null)
                    {
                        user.LastVersion = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location).ProductVersion;
                    }
                    else
                    {
                        user.LastVersion = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).ProductVersion;
                    }
                    using (System.Transactions.TransactionScope transaction = BL.ApplicationDataContext.Instance.DataContext.GetTransactionScope())
                    {
                        BL.ApplicationDataContext.Instance.DataContext.SaveChangesEntitySecurityContext();
                        BL.ApplicationDataContext.Instance.DataContext.CompleteTransaction(transaction);
                    }

                    //// Get the user roles and associated access rights
                    //long[] roleids = BL.ApplicationDataContext.Instance.SecurityEntityContext.SEC_UserRole.Where(n => n.UserId == user.Id).Select(n => n.RoleId).ToArray();
                    //ApplicationDataContext.Instance.AccessIds = BL.ApplicationDataContext.Instance.SecurityEntityContext.SEC_RoleAccess.Where(n => roleids.Contains(n.RoleId)).Select(n => n.AccessId).Distinct().ToArray();

                    return(true);
                }
                else
                {
                    // User provided incorrect credentials
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //if (BusinessLogicExceptionHandler.HandleException(ref ex)) throw ex;
                throw ex.InnerException;
            }
        }
Exemplo n.º 5
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);
            }
        }