Пример #1
0
 /// <summary>
 /// AddUpdateCurrentUser method
 /// </summary>
 /// <param name="asppUser"></param>
 /// <param name="asppGroups"></param>
 /// <param name="simplUser"></param>
 /// <param name="db"></param>
 public void AddUpdateCurrentUser(ASPP_Users asppUser, List<ASPP_Groups> asppGroups, Entity simplUser, SIMPLEntities db)
 {
     // import user information from ASPP db
     simplUser.EntityName1 = asppUser.Last_Name;
     simplUser.EntityName2 = asppUser.First_Name;
     simplUser.EntityTypeId = DetermineEntityType(asppUser, asppGroups, db);
     if (simplUser.EntityTypeId == 0)
         throw new ASPPException("No roles defined for user");
     simplUser.Cbr = asppUser.Phone != null ? Regex.Replace(asppUser.Phone, "[^0-9]", "") : "";
     simplUser.Email = asppUser.Email;
 }
Пример #2
0
        /// <summary>
        /// DetermineEntityType method
        /// </summary>
        /// <param name="user"></param>
        /// <param name="asppGroups"></param>
        /// <param name="sdb"></param>
        /// <returns></returns>
        public int DetermineEntityType(ASPP_Users user, IEnumerable<ASPP_Groups> asppGroups, SIMPLEntities sdb)
        {
            var groupIdList = asppGroups.Select(g => g.Group_ID).ToList();

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Admin))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Admin;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.FieldMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.FieldMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesMgmt))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesMgmt;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.NTElevated))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.NTElevated;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.NT))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.NT;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairHelpdesk))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairHelpdesk;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesHelpdesk))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesHelpdesk;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Collections))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Collections;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Distributor))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Distributor;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Retail))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Retail;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Supply))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Supply;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.Tech))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.Tech;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.RepairAgent))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.RepairAgent;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.SalesAgent))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.SalesAgent;
            }

            if (groupIdList.Contains((int)SIMPLDbEnums.ASPP_SIMPLGroupNumberEnum.ReadOnly))
            {
                return (int)SIMPLDbEnums.EntityTypeEnum.ReadOnly;
            }

            return 0;
        }
Пример #3
0
        /// <summary>
        /// SyncCurrentUser method
        /// </summary>
        /// <param name="asppUser"></param>
        /// <param name="asppGroups"></param>
        /// <param name="userId"></param>
        public void SyncCurrentUser(ASPP_Users asppUser, List<ASPP_Groups> asppGroups, string userId)
        {
            using (var db = DBContextFactory.CreateContext())
            {
                var simplUser = db.Entities.FirstOrDefault(e => e.EntityId == db.UniqueIds.
                    FirstOrDefault(u => u.UniqueIdValue == userId).EntityId);

                // verify/update location information
                SyncLocation(asppUser, simplUser, db);

                //verify/import user information
                AddUpdateCurrentUser(asppUser, asppGroups, simplUser, db);

                // import and overwrite roles list on every login
                SyncRoles(asppGroups, simplUser, db);

                // import UniqueId
                SyncUniqueId(simplUser, db, userId);

                db.SaveChanges();
            }
        }
Пример #4
0
        /// <summary>
        /// Updates the integer LocId value on an Entity entity based on the company_name
        /// field in the ASPP_Users database via a translation table in the simpl db
        /// </summary>
        /// <param name="asppUser"></param>
        /// <param name="simplUser"></param>
        /// <param name="db"></param>
        public void SyncLocation(ASPP_Users asppUser, Entity simplUser, SIMPLEntities db)
        {
            var loc = db.ASPPLocTranslations.FirstOrDefault(l => l.ASPP_Loc == asppUser.Company_Name);
            if (loc == null)
                // User's aspp_location does not exist in the simpl translation table, so throw error and stop run.
                throw new ASPPException("User's location does not exist/is out-of-date. Please submit a support ticket to resolve.");

            // User's aspp_location exists in translation table, so set loc_id to corresponding simpl LocId (int)
            simplUser.LocId = loc.SIMPL_LocId;
        }
Пример #5
0
 /// <summary>
 /// FullUserImport method
 /// </summary>
 /// <param name="ASPPuser"></param>
 /// <param name="asppGroups"></param>
 /// <param name="userId"></param>
 public void FullUserImport(ASPP_Users ASPPuser, List<ASPP_Groups> asppGroups, string userId)
 {
     using (var db = DBContextFactory.CreateContext())
     {
         var newUser = new Entity();
         AddUpdateCurrentUser(ASPPuser, asppGroups, newUser, db);
         db.Entities.AddObject(newUser);
         SyncLocation(ASPPuser, newUser, db);
         SyncRoles(asppGroups, newUser, db);
         SyncUniqueId(newUser, db, userId);
         db.SaveChanges();
     }
 }