예제 #1
0
        /// <summary>
        /// Write Log For UserAdmin
        /// </summary>
        /// <param name="oldInfo"></param>
        /// <param name="newInfo"></param>
        /// <param name="action"></param>
        public void WriteLogForUserAdmin(User_Group oldInfo, User_Group newInfo, ELogAction action)
        {
            try
            {
                if (newInfo == null)
                {
                    return;
                }
                MasterLog objMasterLog = new MasterLog();

                string logId = commonDao.UniqueId;

                switch (action)
                {
                    case ELogAction.Insert:
                        // Insert to Master Log
                        commonDao.InsertMasterLog(logId, newInfo.CreatedBy, ELogTable.UserAdmin.ToString(), action.ToString());
                        // Write Insert Log
                        WriteInsertLogForUserAdmin(newInfo, logId);
                        break;
                    case ELogAction.Update:
                        // Insert to Master Log
                        commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.UserAdmin.ToString(), action.ToString());
                        // Write Update Log
                        bool isUpdated = WriteUpdateLogForUserAdmin(newInfo, logId);
                        if (!isUpdated)
                        {
                            commonDao.DeleteMasterLog(logId);
                        }
                        break;
                    case ELogAction.Delete:
                        // Insert to Master Log
                        commonDao.InsertMasterLog(logId, newInfo.UpdatedBy, ELogTable.UserAdmin.ToString(), action.ToString());
                        // Write Delete Log
                        string key = "User name '" + newInfo.UserAdmin.UserName + "'";
                        commonDao.InsertLogDetail(logId, "UserAdminId", "Key for Delete ", key, null);
                        break;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        //Cuando seleccione uno
        private void lListLogin_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.lListLogin.IsEnabled == true)
            {
                this.lListDestinoUserGroup.Items.Clear();
                int index = this.lListLogin.SelectedIndex;
                this.tUserName.Text = this._listLogin[index].nombre;
                this.tPassword.Text = this._listLogin[index].password;
                User_Group ug = new User_Group(this._listLogin[index].UserGroup.id).findById();
                this.lListDestinoUserGroup.Items.Add(new ListBoxItem()
                {
                    Content = ug.name
                });

                this.btnAdduser.Visibility        = Visibility.Hidden;
                this.btnActualizarUser.Visibility = Visibility.Visible;
                this.workSpace.IsEnabled          = true;
                this.llenaListUserGroup();
            }
        }
예제 #3
0
 /// <summary>
 /// Write Insert Log For UserAdmin
 /// </summary>
 /// <param name="objInfo"></param>
 /// <param name="logId"></param>
 private void WriteInsertLogForUserAdmin(User_Group objInfo, string logId)
 {
     try
     {
         if ((objInfo != null) && (logId != null))
         {
             // Insert to Log Detail
             commonDao.InsertLogDetail(logId, "UserName", "User Name", null, objInfo.UserAdmin.UserName);
             if (!string.IsNullOrEmpty(objInfo.UserAdmin.UserName))
             {
                 commonDao.InsertLogDetail(logId, "UserName", "UserName", null, objInfo.UserAdmin.UserName);
             }
             commonDao.InsertLogDetail(logId, "GroupId", "Group", null, objInfo.Group.GroupName);
             commonDao.InsertLogDetail(logId, "IsActive", "Active", null, objInfo.IsActive.ToString());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
예제 #4
0
        /// <summary>
        /// Get User Group  by user Code
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <returns>User_Group</returns>
        public User_Group GetUserGroup(string userCode)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,UserService,GetUserGroup,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            var userGroup = new User_Group();
            var query     =
                $"select Uig.UGroup, UGroup.UG_Name, UGroup.SecurityLevel From Uig INNER JOIN UGroup ON Uig.UGroup = UGroup.UGroup Where  Uig.[User] = '{userCode}'";
            var dt = GetRecords(query, DataSource.CSCAdmin);

            if (dt != null && dt.Rows.Count > 0)
            {
                userGroup.Code          = CommonUtility.GetStringValue(dt.Rows[0]["UGroup"]);
                userGroup.Name          = CommonUtility.GetStringValue(dt.Rows[0]["UG_Name"]);
                userGroup.SecurityLevel = CommonUtility.GetByteValue(dt.Rows[0]["SecurityLevel"]);
            }
            _performancelog.Debug($"End,TillService,GetUserGroup,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(userGroup);
        }
        /// <summary>
        /// This method returns created group details
        /// </summary>
        /// <param name="group"></param>
        /// <returns> created group  object</returns>

        /*  public Group CreateGroup(Group group)
         * {
         *
         *
         *    db.Groups.Add(group);
         *
         *    try
         *    {
         *        db.SaveChanges();
         *    }
         *    catch (DbUpdateException)
         *    {
         *        if (GroupExists(group.id))
         *        {
         *            throw new Exception("Conflit");
         *        }
         *        else
         *        {
         *            throw;
         *        }
         *    }
         *
         *    return group;
         * }*/


        public Group CreateGroup(GroupDetails gd)
        {
            LinkedList <User_Group> grps = new LinkedList <User_Group>();

            foreach (UserDetails ud in gd.UserList)
            {
                User_Group userGrp = new User_Group();
                userGrp.user_id = (db.Users.Where(user => user.emailId == ud.emailId).FirstOrDefault()).id;
                grps.AddLast(userGrp);
            }

            Group group = new Group();

            group.name       = gd.group.name;
            group.createdby  = gd.group.createdby;
            group.User_Group = grps;

            db.Groups.Add(group);
            db.SaveChanges();

            return(group);
        }
예제 #6
0
 private void btnAdduser_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (!this.tUserName.Text.Trim().Equals(""))
     {
         if (!this.tPassword.Text.Trim().Equals(""))
         {
             if (this.lListDestinoUserGroup.Items.Count > 0)
             {
                 QuestionDialog pregunta = new QuestionDialog("Realmente desea Agregar estos privilegios a " + this.tUserName.Text, main);
                 pregunta.ShowDialog();
                 if (pregunta.DialogResult == true)
                 {
                     foreach (ListBoxItem UserGroups in this.lListDestinoUserGroup.Items)
                     {
                         User_Group ug = new User_Group(new User_Group(UserGroups.Content.ToString()).getIdByName());
                         if (new Login(this.tUserName.Text.Trim(), this.tPassword.Text.Trim(), ug).save() > 0)//si no existe el privilegio
                         {
                             this.llenaListLogin();
                             this.lListLogin.IsEnabled = true;
                         }
                     }
                 }
             }
             else
             {
                 new Dialog("Seleccione un grupo de usuario a asignar.", main).ShowDialog();
             }
         }
         else
         {
             new Dialog("Rellene campo Password", main).ShowDialog();
         }
     }
     else
     {
         new Dialog("Rellene campo User Name", main).ShowDialog();
     }
 }
예제 #7
0
        public bool Quit(int groupId)
        {
            var path = Request.Path;

            string[] splitted = path.Value.Split('/');
            groupId = int.Parse(splitted.Last());
            // Not authentified
            if (!Authenticate())
            {
                return(false);
            }

            // Remove user from group if he is
            User_Group uGroup = context.User_Groups.FirstOrDefault(ug => ug.GroupId == groupId && ug.UserId == RequestUserId);

            if (uGroup != null)
            {
                context.User_Groups.Remove(uGroup);
                context.SaveChanges();
            }

            return(true);
        }
예제 #8
0
        private void btnDeleteStudentFormGroup_Click(object sender, EventArgs e)
        {
            User_Group UserGroup = new User_Group();

            UserGroup.GroupID  = txtGroupID.Text;
            UserGroup.UserName = GridViewDetail.Rows[GridViewDetail.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim();

            User_Group_Data UserGroupData = new User_Group_Data();

            try
            {
                if (UserGroupData.checkDeleteUser_Group(UserGroup))
                {
                    MessageBox.Show("Delete Student in list Complete!");
                    bsUser_Group.DataSource   = UserGroupData.getListUser_Group(UserGroup.GroupID);
                    GridViewDetail.DataSource = bsUser_Group;
                }
            }
            catch
            {
                MessageBox.Show("Delete Student in list Fail!");
            }
        }
예제 #9
0
        private void insertar(object sender, MouseButtonEventArgs e)
        {
            String     nombre = this.tAddGroup.Text;
            User_Group ug     = new User_Group(nombre);

            if (ug.ifExist() < 1)
            {
                if (ug.save() != 0)
                {
                    this.tAddGroup.Text = "";
                    new Dialog("Grupo agregado correctamente", main).ShowDialog();
                }
                else
                {
                    new Dialog("Error en agregar grupo", main).ShowDialog();
                }
            }
            else
            {
                this.tAddGroup.Text = "";
                new Dialog("El Grupo ya existe, ingrese otro nombre.", main).ShowDialog();
            }
        }
예제 #10
0
        public bool checkDeleteUser_Group(User_Group UserGroup)
        {
            string SQL = "Delete from User_Group where UserName = @UserName and GroupID = @GroupID";
            bool   check;

            try
            {
                cnn = new SqlConnection(strConnection);
                SqlCommand cmd = new SqlCommand(SQL, cnn);
                cmd.Parameters.AddWithValue("@UserName", UserGroup.UserName);
                cmd.Parameters.AddWithValue("@GroupID", UserGroup.GroupID);
                cnn.Open();
                check = cmd.ExecuteNonQuery() > 0;
            }
            catch
            {
                throw new Exception();
            }
            finally
            {
                cnn.Close();
            }
            return(check);
        }
        /// <summary> Constructor for a new instance of the User_Group_AdminViewer class </summary>
        /// <param name="User"> Authenticated user information </param>
        /// <param name="currentMode"> Mode / navigation information for the current request</param>
        /// <param name="Code_Manager"> List of valid collection codes, including mapping from the Sobek collections to Greenstone collections</param>
        /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param>
        /// <remarks> Postback from a user group edit is handled here in the constructor </remarks>
        public User_Group_AdminViewer(User_Object User, SobekCM_Navigation_Object currentMode, Aggregation_Code_Manager Code_Manager, Custom_Tracer Tracer)
            : base(User)
        {
            Tracer.Add_Trace("User_Group_AdminViewer.Constructor", String.Empty);

            // Set the action message to clear initially
            actionMessage = String.Empty;
            codeManager   = Code_Manager;

            // Get the user to edit, if there was a user id in the submode
            int edit_usergroupid = -100;

            editGroup = null;
            if (currentMode.My_Sobek_SubMode.Length > 0)
            {
                if (currentMode.My_Sobek_SubMode == "new")
                {
                    edit_usergroupid = -1;
                }
                else
                {
                    if (Int32.TryParse(currentMode.My_Sobek_SubMode.Replace("a", "").Replace("b", "").Replace("c", "").Replace("v", ""), out edit_usergroupid))
                    {
                        editGroup = SobekCM_Database.Get_User_Group(edit_usergroupid, Tracer);
                    }
                }
            }

            // Determine the mode
            mode = Users_Group_Admin_Mode_Enum.Error;
            if ((editGroup != null) || (edit_usergroupid == -1))
            {
                if ((currentMode.My_Sobek_SubMode.IndexOf("v") > 0) && (edit_usergroupid > 0))
                {
                    mode = Users_Group_Admin_Mode_Enum.View_User_Group;
                }
                else
                {
                    mode = Users_Group_Admin_Mode_Enum.Edit_User_Group;
                }
            }
            else
            {
                currentMode.My_Sobek_SubMode = String.Empty;
                currentMode.Admin_Type       = Admin_Type_Enum.Users;
                HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
            }

            // Set an empty user group object for a new item
            if (edit_usergroupid < 0)
            {
                editGroup = new User_Group(String.Empty, String.Empty, -1);
            }

            // Perform post back work
            if (currentMode.isPostBack)
            {
                if ((mode == Users_Group_Admin_Mode_Enum.Edit_User_Group) && (editGroup != null))
                {
                    // Get a reference to this form
                    NameValueCollection form    = HttpContext.Current.Request.Form;
                    string[]            getKeys = form.AllKeys;

                    bool successful_save = true;
                    bool can_editall     = editGroup.Editable_Regular_Expressions.Any(thisRegularExpression => thisRegularExpression == "[A-Z]{2}[A-Z|0-9]{4}[0-9]{4}");

                    bool   can_submit  = false;
                    bool   is_internal = false;
                    bool   is_admin    = false;
                    bool   is_portal   = false;
                    string name        = editGroup.Name;
                    string description = editGroup.Description;

                    List <string> projects  = new List <string>();
                    List <string> templates = new List <string>();

                    Dictionary <string, User_Editable_Aggregation> aggregations = new Dictionary <string, User_Editable_Aggregation>();

                    // Step through each key
                    foreach (string thisKey in getKeys)
                    {
                        switch (thisKey)
                        {
                        case "groupName":
                            name = form[thisKey].Trim();
                            break;

                        case "groupDescription":
                            description = form[thisKey].Trim();
                            break;

                        case "admin_user_submit":
                            can_submit = true;
                            break;

                        case "admin_user_internal":
                            is_internal = true;
                            break;

                        case "admin_user_editall":
                            can_editall = true;
                            break;

                        case "admin_user_admin":
                            is_admin = true;
                            break;

                        case "admin_user_portaladmin":
                            is_portal = true;
                            break;

                        default:
                            if (thisKey.IndexOf("admin_user_template_") == 0)
                            {
                                templates.Add(thisKey.Replace("admin_user_template_", ""));
                            }
                            if (thisKey.IndexOf("admin_user_project_") == 0)
                            {
                                projects.Add(thisKey.Replace("admin_user_project_", ""));
                            }
                            if (thisKey.IndexOf("admin_project_onhome_") == 0)
                            {
                                string select_project = thisKey.Replace("admin_project_onhome_", "");
                                if (aggregations.ContainsKey(select_project))
                                {
                                    aggregations[select_project].OnHomePage = true;
                                }
                                else
                                {
                                    aggregations.Add(select_project, new User_Editable_Aggregation(select_project, String.Empty, false, false, false, true));
                                }
                            }
                            if (thisKey.IndexOf("admin_project_select_") == 0)
                            {
                                string select_project = thisKey.Replace("admin_project_select_", "");
                                if (aggregations.ContainsKey(select_project))
                                {
                                    aggregations[select_project].CanSelect = true;
                                }
                                else
                                {
                                    aggregations.Add(select_project, new User_Editable_Aggregation(select_project, String.Empty, true, false, false, false));
                                }
                            }
                            if (thisKey.IndexOf("admin_project_edit_") == 0)
                            {
                                string edit_project = thisKey.Replace("admin_project_edit_", "");
                                if (aggregations.ContainsKey(edit_project))
                                {
                                    aggregations[edit_project].CanEditItems = true;
                                }
                                else
                                {
                                    aggregations.Add(edit_project, new User_Editable_Aggregation(edit_project, String.Empty, false, true, false, false));
                                }
                            }
                            if (thisKey.IndexOf("admin_project_admin_") == 0)
                            {
                                string admin_project = thisKey.Replace("admin_project_admin_", "");
                                if (aggregations.ContainsKey(admin_project))
                                {
                                    aggregations[admin_project].IsCurator = true;
                                }
                                else
                                {
                                    aggregations.Add(admin_project, new User_Editable_Aggregation(admin_project, String.Empty, false, false, true, false));
                                }
                            }
                            break;
                        }
                    }

                    // Determine if the projects and templates need to be updated
                    bool update_templates_projects = false;
                    if ((templates.Count != editGroup.Templates.Count) || (projects.Count != editGroup.Projects.Count))
                    {
                        update_templates_projects = true;
                    }
                    else
                    {
                        // Check all of the templates
                        if (templates.Any(template => !editGroup.Templates.Contains(template)))
                        {
                            update_templates_projects = true;
                        }

                        // Check all the projects
                        if (!update_templates_projects)
                        {
                            if (projects.Any(project => !editGroup.Projects.Contains(project)))
                            {
                                update_templates_projects = true;
                            }
                        }
                    }

                    // Determine if the aggregations need to be edited
                    bool update_aggregations = false;
                    if (aggregations.Count != editGroup.Aggregations.Count)
                    {
                        update_aggregations = true;
                    }
                    else
                    {
                        // Build a dictionary of the user aggregations as well
                        Dictionary <string, User_Editable_Aggregation> existingAggr = editGroup.Aggregations.ToDictionary(thisAggr => thisAggr.Code);

                        // Check all the aggregations
                        foreach (User_Editable_Aggregation adminAggr in aggregations.Values)
                        {
                            if (existingAggr.ContainsKey(adminAggr.Code))
                            {
                                if ((adminAggr.CanSelect != existingAggr[adminAggr.Code].CanSelect) || (adminAggr.CanEditItems != existingAggr[adminAggr.Code].CanEditItems) || (adminAggr.IsCurator != existingAggr[adminAggr.Code].IsCurator))
                                {
                                    update_aggregations = true;
                                    break;
                                }
                            }
                            else
                            {
                                update_aggregations = true;
                                break;
                            }
                        }
                    }

                    // Must have a name to continue
                    if (name.Length > 0)
                    {
                        // Update the basic user information
                        int newid = SobekCM_Database.Save_User_Group(editGroup.UserGroupID, name, description, can_submit, is_internal, can_editall, is_admin, is_portal, false, update_templates_projects, update_aggregations, false, Tracer);
                        if (editGroup.UserGroupID < 0)
                        {
                            editGroup.UserGroupID = newid;
                        }

                        if (editGroup.UserGroupID > 0)
                        {
                            // Update the templates and projects, if requested
                            if (update_templates_projects)
                            {
                                // Update projects, if necessary
                                if (projects.Count > 0)
                                {
                                    if (!SobekCM_Database.Update_SobekCM_User_Group_Projects(editGroup.UserGroupID, projects, Tracer))
                                    {
                                        successful_save = false;
                                    }
                                }

                                // Update templates, if necessary
                                if (templates.Count > 0)
                                {
                                    if (!SobekCM_Database.Update_SobekCM_User_Group_Templates(editGroup.UserGroupID, templates, Tracer))
                                    {
                                        successful_save = false;
                                    }
                                }
                            }

                            // Update the aggregations, if requested
                            if (update_aggregations)
                            {
                                if (aggregations.Count > 0)
                                {
                                    List <User_Editable_Aggregation> aggregationList = aggregations.Values.ToList();
                                    if (!SobekCM_Database.Update_SobekCM_User_Group_Aggregations(editGroup.UserGroupID, aggregationList, Tracer))
                                    {
                                        successful_save = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            successful_save = false;
                        }
                    }
                    else
                    {
                        actionMessage   = "User group's name must have a length greater than zero";
                        successful_save = false;
                    }

                    // Forward back to the list of users, if this was successful
                    if (successful_save)
                    {
                        currentMode.My_Sobek_SubMode = String.Empty;
                        HttpContext.Current.Response.Redirect(currentMode.Redirect_URL());
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Write Update Log For UserAdmin
        /// </summary>
        /// <param name="newInfo"></param>
        /// <param name="logId"></param>
        /// <returns></returns>
        private bool WriteUpdateLogForUserAdmin(User_Group newInfo, string logId)
        {
            bool isUpdated = false;
            try
            {
                // Get old info
                User_Group oldInfo = dao.GetUser_Group(newInfo.ID);

                if ((oldInfo != null) && (newInfo != null) && (logId != null))
                {
                    if (!newInfo.UserAdmin.UserName.Equals(oldInfo.UserAdmin.UserName))
                    {
                        commonDao.InsertLogDetail(logId, "UserName", "User Name", oldInfo.UserAdmin.UserName, newInfo.UserAdmin.UserName);
                        isUpdated = true;
                    }

                    if (newInfo.GroupId != oldInfo.GroupId)
                    {
                        commonDao.InsertLogDetail(logId, "Group", "Group", oldInfo.Group.GroupName, new GroupDao().GetById(newInfo.GroupId).GroupName);
                        isUpdated = true;
                    }
                    if (newInfo.IsActive != oldInfo.IsActive)
                    {
                        commonDao.InsertLogDetail(logId, "IsActive", "IsActive", oldInfo.IsActive.ToString(), newInfo.IsActive.ToString());
                        isUpdated = true;
                    }

                    if (isUpdated)
                    {
                        // Insert Key Name
                        string key = "User name '" + oldInfo.UserAdmin.UserName + "'";
                        commonDao.InsertLogDetail(logId, "UserAdminId", "Key for Update", key, null);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return isUpdated;
        }
 public virtual long Save(object _model)
 {
     var id = Service.Save(_model);
        if (id > 0)
        {
        var user =(User)_model;
        User_Group g = new User_Group();
        g.GroupID = user.GroupIDExt;
        g.UserID = id;
        GroupService.Save(g);
        EmailService.Save((user).Email);
        var module = ModuleService.GetList();
        var check = RoleService.GetListByLINQ(c => c.UserID.Equals(id));
        if (check == null||check.Count==0)
        {
            foreach (var item in module)
            {
                User_Role_Module m = new User_Role_Module();
                m.UserID = id;
                m.ModuleID = item.ID;
                m.Role = "";
                RoleService.Save(m);
            }
        }
        }
        return id;
 }
 public virtual void Update(User_Group obj)
 {
     DbSet.Update(obj);
 }
 public virtual void Add(User_Group obj)
 {
     DbSet.Add(obj);
 }
예제 #16
0
        /// <summary>
        /// Insert user admin and user group
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="groupId"></param>
        /// <param name="isActive"></param>
        /// <param name="principal"></param>
        /// <returns></returns>
        public Message Insert(string userName, string groupId, bool isActive, AuthenticationProjectPrincipal principal)
        {
            Message msg = null;
            try
            {
                if (auDao.CheckExistInAD(userName))
                {
                    UserAdmin user = GetByUserName(userName);
                    if (user == null)
                    {
                        user = new UserAdmin();
                        user.UserName = userName;
                        user.DeleteFlag = false;
                        user.CreateDate = DateTime.Now;
                        user.UpdateDate = DateTime.Now;
                        user.CreatedBy = principal.UserData.UserName;
                        user.UpdatedBy = principal.UserData.UserName;

                        dbContext.UserAdmins.InsertOnSubmit(user);
                        dbContext.SubmitChanges();
                    }

                    int _groupId = int.Parse(groupId);

                    User_Group user_group = GetUser_Group(user.UserAdminId, _groupId);
                    if (user_group == null)
                    {
                        user_group = new User_Group();
                        user_group.UserAdminId = user.UserAdminId;
                        user_group.GroupId = int.Parse(groupId);
                        user_group.IsActive = isActive;
                        user_group.CreateDate = DateTime.Now;
                        user_group.UpdateDate = DateTime.Now;
                        user_group.CreatedBy = principal.UserData.UserName;
                        user_group.UpdatedBy = principal.UserData.UserName;

                        dbContext.User_Groups.InsertOnSubmit(user_group);
                        dbContext.SubmitChanges();

                        //Write Log
                        new UserAdminLogDao().WriteLogForUserAdmin(null, user_group, ELogAction.Insert);

                        msg = new Message(MessageConstants.I0001, MessageType.Info, "User " + userName + " belong group " + user_group.Group.GroupName, "added");
                    }
                    else
                    {
                        //msg = new Message(MessageConstants.E0020, MessageType.Error, "User " + userName + " belong group " + user_group.Group.GroupName, "database");
                        msg = new Message(MessageConstants.E0020, MessageType.Error, "User " + userName, "group " + user_group.Group.GroupName);
                    }
                }
                else
                {
                    msg = new Message(MessageConstants.E0005, MessageType.Error, "User " + userName, "Active Directory");
                }
            }
            catch (Exception)
            {
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }
            return msg;
        }