internal void FromGroupLevel(GroupLevel gl)
        {
            this.SetAllNull();

            if (gl.UniqueName != null) this.UniqueName = gl.UniqueName.Value;
            if (gl.Caption != null) this.Caption = gl.Caption.Value;
            if (gl.User != null) this.User = gl.User.Value;
            if (gl.CustomRollUp != null) this.CustomRollUp = gl.CustomRollUp.Value;

            if (gl.Groups != null)
            {
                SLGroup g;
                using (OpenXmlReader oxr = OpenXmlReader.Create(gl.Groups))
                {
                    while (oxr.Read())
                    {
                        if (oxr.ElementType == typeof(Group))
                        {
                            g = new SLGroup();
                            g.FromGroup((Group)oxr.LoadCurrentElement());
                            this.Groups.Add(g);
                        }
                    }
                }
            }
        }
        internal GroupLevel ToGroupLevel()
        {
            var gl = new GroupLevel();

            gl.UniqueName = UniqueName;
            gl.Caption    = Caption;
            if (User)
            {
                gl.User = User;
            }
            if (CustomRollUp)
            {
                gl.CustomRollUp = CustomRollUp;
            }

            if (Groups.Count > 0)
            {
                gl.Groups = new Groups {
                    Count = (uint)Groups.Count
                };
                foreach (var g in Groups)
                {
                    gl.Groups.Append(g.ToGroup());
                }
            }

            return(gl);
        }
        internal GroupLevel ToGroupLevel()
        {
            GroupLevel gl = new GroupLevel();

            gl.UniqueName = this.UniqueName;
            gl.Caption    = this.Caption;
            if (this.User != false)
            {
                gl.User = this.User;
            }
            if (this.CustomRollUp != false)
            {
                gl.CustomRollUp = this.CustomRollUp;
            }

            if (this.Groups.Count > 0)
            {
                gl.Groups = new Groups()
                {
                    Count = (uint)this.Groups.Count
                };
                foreach (SLGroup g in this.Groups)
                {
                    gl.Groups.Append(g.ToGroup());
                }
            }

            return(gl);
        }
示例#4
0
        public ActionResult DeleteConfirmed(long id)
        {
            GroupLevel groupLevel = db.GroupLevel.Find(id);

            db.GroupLevel.Remove(groupLevel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#5
0
        private async Task AddGroupLevel(Command request, GroupClassAggregate groupClass, CancellationToken cancellationToken)
        {
            if (request.GroupLevelId != default)
            {
                GroupLevel groupLevel = await _context.GroupLevel.Where(x => x.Id == request.GroupLevelId.Value)
                                        .FirstOrDefaultAsync(cancellationToken);

                groupClass.WithGroupLevel(groupLevel);
            }
        }
示例#6
0
        private async Task UpdateGroupLevel(Command request, Model.Domain.GroupClass groupClass, GroupClassAggregate groupClassAggregate,
                                            CancellationToken cancellationToken)
        {
            if (request.GroupLevelId != default && request.GroupLevelId != groupClass.GroupLevel?.Id)
            {
                GroupLevel groupLevel = await _context.GroupLevel.Where(x => x.Id == request.GroupLevelId.Value)
                                        .FirstOrDefaultAsync(cancellationToken);

                groupClassAggregate.WithGroupLevel(groupLevel);
            }
        }
示例#7
0
 public ActionResult Edit([Bind(Include = "id,id_group,id_parent,remark")] GroupLevel groupLevel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(groupLevel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.parent   = db.GroupLevel.Include(g => g.GroupLevel2).Include(g => g.Groups).Where(a => a.id_parent == null).ToList();
     ViewBag.id_group = new SelectList(db.Groups, "id", "name", groupLevel.id_group);
     return(View("~/Views/appdashboard/adminsystem/GroupLevel/Edit.cshtml", groupLevel));
 }
示例#8
0
 private Group Create(string name, string code, GroupLevel level, string email, string contact, Group parent)
 {
     return new Group
     {
         Name = name,
         Code = code,
         Level = level,
         Email = email,
         Contact = contact,
         Parent = parent,
         SecurityKey = new SecurityKey(level, parent)
     };
 }
示例#9
0
        // GET: GroupLevels/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupLevel groupLevel = db.GroupLevel.Find(id);

            if (groupLevel == null)
            {
                return(HttpNotFound());
            }
            return(View("~/Views/appdashboard/adminsystem/GroupLevel/Delete.cshtml", groupLevel));
        }
示例#10
0
        // GET: GroupLevels/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GroupLevel groupLevel = db.GroupLevel.Find(id);

            if (groupLevel == null)
            {
                return(HttpNotFound());
            }
            ViewBag.parent   = db.GroupLevel.Include(g => g.GroupLevel2).Include(g => g.Groups).Where(a => a.id_parent == null).ToList();
            ViewBag.id_group = new SelectList(db.Groups, "id", "name", groupLevel.id_group);
            return(View("~/Views/appdashboard/adminsystem/GroupLevel/Edit.cshtml", groupLevel));
        }
示例#11
0
        public static String GetGroupLevelName(GroupLevel groupLevel)
        {
            string ret = "GENERALLY";

            switch (groupLevel)
            {
            case GroupLevel.EXTREMELY:
                ret = "EXTREMELY";
                break;

            case GroupLevel.IMPORTANTLY:
                ret = "IMPORTANTLY";
                break;

            case GroupLevel.GENERALLY:
                ret = "GENERALLY";
                break;
            }
            return(ret);
        }
        internal void FromGroupLevel(GroupLevel gl)
        {
            this.SetAllNull();

            if (gl.UniqueName != null)
            {
                this.UniqueName = gl.UniqueName.Value;
            }
            if (gl.Caption != null)
            {
                this.Caption = gl.Caption.Value;
            }
            if (gl.User != null)
            {
                this.User = gl.User.Value;
            }
            if (gl.CustomRollUp != null)
            {
                this.CustomRollUp = gl.CustomRollUp.Value;
            }

            if (gl.Groups != null)
            {
                SLGroup g;
                using (OpenXmlReader oxr = OpenXmlReader.Create(gl.Groups))
                {
                    while (oxr.Read())
                    {
                        if (oxr.ElementType == typeof(Group))
                        {
                            g = new SLGroup();
                            g.FromGroup((Group)oxr.LoadCurrentElement());
                            this.Groups.Add(g);
                        }
                    }
                }
            }
        }
示例#13
0
        /// <summary>
        /// Adds a user with a specified administrative level to a group.
        /// </summary>
        /// <param name="groupID">The GroupID of the group to add the user to.</param>
        /// <param name="userID">The UserID of the user to add.</param>
        /// <param name="groupLevel">The level of the user's permissions in the group.</param>
        /// <returns>true if the user was added successfully.</returns>
        /// <exception cref="ArgumentNullException">If the given groupID or userID are null.</exception>
        /// <seealso cref="GroupLevel"/>
        public bool AddMemberToGroup(int? groupID, int? userID, GroupLevel groupLevel)
        {
            if (null == groupID || null == userID) throw new ArgumentNullException("Cannot add null userID, or add user to null groupID.");

            return InsertGroupMember(groupID, userID, groupLevel);
        }
示例#14
0
        /// <summary>
        /// Inserts a list of records into the "groupmembers" table for a specific group and group level.
        /// </summary>
        /// <param name="groupID">The associated group for a list of users.</param>
        /// <param name="users">The list of users in the group.</param>
        /// <param name="groupLevel">The group level of the users.</param>
        private bool InsertGroupMembers(int? groupID, HashSet<UserDAO> users, GroupLevel groupLevel)
        {
            foreach(UserDAO user in users)
            {
                if (!UserExists(user.UserName, user.PhoneEmail)) throw new CouldNotFindException("User with username: "******" needs to be created before being added to the group.");
                if (!InsertGroupMember(groupID, user.UserID, groupLevel)) return false;
            }

            return true;
        }
示例#15
0
        /// <summary>
        /// Inserts an individual record into the "groupmembers" table for a specific group and group level.
        /// </summary>
        /// <param name="groupID">The associated group for a user.</param>
        /// <param name="userID">The userID for a specific user.</param>
        /// <param name="groupLevel">The group level of the user.</param>
        private bool InsertGroupMember(int? groupID, int? userID, GroupLevel groupLevel)
        {
            using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
            using (SqlCommand query = conn.CreateCommand())
            {
                StringBuilder queryBuilder = new StringBuilder();
                queryBuilder.Append("INSERT INTO groupmembers (group_id, user_id, group_level, added_dt) ");
                queryBuilder.Append("VALUES ");
                queryBuilder.Append("(@group_id, @user_id, @group_level, GETDATE())");

                query.CommandText = queryBuilder.ToString();
                query.Parameters.AddWithValue("@group_id", groupID);
                query.Parameters.AddWithValue("@user_id", userID);
                query.Parameters.AddWithValue("@group_level", (int)groupLevel);

                conn.Open();
                int effectedRows = query.ExecuteNonQuery();

                return 1 == effectedRows;
            }
        }
示例#16
0
        /// <summary>
        /// Gets a list of groups for a particular user based on a specific GroupLevel the user might be.
        /// </summary>
        /// <param name="userid">The id of the user to search for.</param>
        /// <param name="level">The GroupLevel the user is at within each group.</param>
        /// <returns>A list containing all groups with the user at the given level.</returns>
        private List<GroupDAO> GetGroupsForUserWithGroupLevel(int? userid, GroupLevel level)
        {
            if (null == userid) throw new ArgumentNullException("Cannot get information for null user.");

            using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
            using (SqlCommand query = conn.CreateCommand())
            {
                StringBuilder queryBuilder = new StringBuilder();
                queryBuilder.Append("SELECT grouptag FROM groups g ");
                queryBuilder.Append("INNER JOIN groupmembers gm ON g.id = gm.group_id ");
                queryBuilder.Append("WHERE gm.user_id = @userid AND gm.group_level = @grouplevel ");

                query.CommandText = queryBuilder.ToString();
                query.Parameters.AddWithValue("@userid", userid);
                query.Parameters.AddWithValue("@grouplevel", level);

                conn.Open();
                SqlDataReader reader = query.ExecuteReader();

                List<GroupDAO> groups = new List<GroupDAO>();
                while (reader.Read())
                {
                    groups.Add(RetrieveGroup((string)reader["grouptag"]));
                }

                return groups;
            }
        }
示例#17
0
        private List<UserDAO> GetAllGroupMembers(int? groupID, bool byGroupLevel, GroupLevel groupLevel)
        {
            List<int?> userIDList = GetAllGroupMemberIDs(groupID, byGroupLevel, groupLevel);
            List<UserDAO> userList = new List<UserDAO>();
            foreach (int? id in userIDList) userList.Add(RetrieveUser(id));

            return userList;
        }
示例#18
0
 public ScanSignal(String jobName, GroupLevel groupLevel, int milliseconds)
 {
     this.JobName    = jobName;
     this.GroupLevel = groupLevel;
     this.TimeSpan   = new TimeSpan(0, 0, 0, 0, milliseconds);
 }
示例#19
0
        internal GroupLevel ToGroupLevel()
        {
            GroupLevel gl = new GroupLevel();
            gl.UniqueName = this.UniqueName;
            gl.Caption = this.Caption;
            if (this.User != false) gl.User = this.User;
            if (this.CustomRollUp != false) gl.CustomRollUp = this.CustomRollUp;

            if (this.Groups.Count > 0)
            {
                gl.Groups = new Groups() { Count = (uint)this.Groups.Count };
                foreach (SLGroup g in this.Groups)
                {
                    gl.Groups.Append(g.ToGroup());
                }
            }

            return gl;
        }
示例#20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="jobName">第一个任务名</param>
 /// <param name="groupLevel">任务组等级</param>
 /// <param name="cronExpression"></param>
 public ScanSignal(String jobName, GroupLevel groupLevel, String cronExpression)
 {
     this.JobName        = jobName;
     this.GroupLevel     = groupLevel;
     this.CronExpression = cronExpression;
 }
示例#21
0
        private void CheckForUserListModifications(int? groupID, HashSet<UserDAO> userList, GroupLevel groupLevel)
        {
            // Get the current list of all users for a specific group level
            List<int?> userIDList = GetAllGroupMemberIDs(groupID, true, groupLevel);

            // For each user in the current group object
            foreach (UserDAO user in userList)
                // If the user is not already a member in the database, add them
                if (!userIDList.Contains(user.UserID)) AddMemberToGroup(groupID, user.UserID, groupLevel);
                // Otherwise, remove their ID from the list
                else userIDList.Remove(user.UserID);

            // At this point, userIDList contains user IDs of members who are no longer in the group
            if (userIDList.Count > 0)
                // For each user no longer in the group
                foreach (int? id in userIDList)
                    // Remove them from the group in the database
                    RemoveMemberFromGroup(groupID, id);
        }
示例#22
0
        private List<int?> GetAllGroupMemberIDs(int? groupID, bool byGroupLevel, GroupLevel groupLevel)
        {
            if (null == groupID) throw new ArgumentNullException();

            using (SqlConnection conn = new SqlConnection(CONNECTION_STRING))
            using (SqlCommand query = conn.CreateCommand())
            {
                StringBuilder queryBuilder = new StringBuilder();
                queryBuilder.Append("SELECT user_id FROM groupmembers ");
                queryBuilder.Append("WHERE group_id = @group_id ");
                if (byGroupLevel)
                    queryBuilder.Append("AND group_level = @group_level");

                query.CommandText = queryBuilder.ToString();
                query.Parameters.AddWithValue("@group_id", groupID);
                if (byGroupLevel)
                    query.Parameters.AddWithValue("@group_level", (int)groupLevel);

                conn.Open();
                SqlDataReader reader = query.ExecuteReader();

                List<int?> userList = new List<int?>();
                while (reader.Read())
                {
                    userList.Add((int?)reader["user_id"]);
                }

                return userList;
            }
        }
示例#23
0
 public GroupClassAggregate WithGroupLevel(GroupLevel groupLevel)
 {
     State.GroupLevel = groupLevel;
     return(this);
 }