public void PushLog(string ObjectUser, string SubjectUser, int type)
        {
            ActivityLog a = new ActivityLog();
            a.ObjectUser = ObjectUser;
            a.SubjectUser = SubjectUser;
            a.ActivityLogTypeId = type;
            a.ActivityDate = DateTime.Now;

            db.ActivityLogs.InsertOnSubmit(a);
            db.SubmitChanges();
        }
        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            string userName = ((HiddenField)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["DeptId"], "hidUserName")).Value;
                int DeptId = Convert.ToInt32(((HiddenField)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["DeptId"], "hidDeptId")).Value);
                int NewDeptId = Convert.ToInt32(((ASPxComboBox)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["DeptId"], "ddDeptId")).Value);
                int UserLevelId = Convert.ToInt32(((ASPxComboBox)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["UserLevelId"], "ddUserLevelId")).Value);
                int hidOldUserLevelId = Convert.ToInt32(((HiddenField)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["UserLevelId"], "hidOldUserLevelId")).Value);

                int Oldstatus = Convert.ToInt32(((HiddenField)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["StatusId"], "hidStatusId")).Value);
                int Newstatus = Convert.ToInt32(((ASPxComboBox)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["StatusId"], "ddStatusId")).Value);

                // Change Level to Professor
                if (hidOldUserLevelId != UserLevelId)
                {
                    // Change to Dean or Header
                    if (UserLevelId != 2)
                    {
                        // There are some one in the position

                        if (UserLevelId == 0)
                        {
                            var q = from p in db.Users
                                    where p.UserLevelId == UserLevelId
                                    select p;

                            foreach (var item in q.ToList())
                            {
                                var r = (from p in db.Users
                                         where p.UserName == item.UserName
                                         select p).First();

                                r.UserLevelId = 2;
                                db.SubmitChanges();

                                AddRole(item.UserName, "Professor");
                            }

                            AddRole(userName, "Dean");
                        }
                        else
                        {
                            var q = from p in db.Users
                                    where p.DeptId == DeptId
                                    where p.UserLevelId == UserLevelId
                                    select p;

                            foreach (var item in q.ToList())
                            {
                                // Change at user
                                var r = (from p in db.Users
                                         where p.UserName == item.UserName
                                         select p).First();

                                r.UserLevelId = 2;
                                db.SubmitChanges();

                                AddRole(item.UserName, "Professor");
                            }

                            AddRole(userName, "Header");
                        }
                    }
                    // Change to Professor
                    else
                    {
                        AddRole(userName, "Professor");
                    }
                }
                else
                {
                    var r = (from p in db.Users
                             where p.UserName == userName
                             select p).First();

                    r.UserLevelId = 2;
                    ((ASPxComboBox)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["UserLevelId"], "ddUserLevelId")).SelectedIndex = 2;
                    db.SubmitChanges();

                    AddRole(userName, "Professor");
                }

                if (Oldstatus != Newstatus)
                {
                    ActivityLog x = new ActivityLog();
                    x.ObjectUser = userName;
                    x.SubjectUser = HttpContext.Current.User.Identity.Name;
                    x.ActivityLogTypeId = 0; // 0 : Cancle user
                    x.ActivityDate = DateTime.Now;

                    of.ActivityLogs.InsertOnSubmit(x);
                    of.SubmitChanges();
                }
        }
        protected void btnResetPassword_Click(object sender, EventArgs e)
        {
            string userName = ((HiddenField)ASPxGridView1.FindEditRowCellTemplateControl((GridViewDataColumn)ASPxGridView1.Columns["DeptId"], "hidUserName")).Value;
            string password = "******";
            MembershipUser mu = Membership.GetUser(userName);
            mu.ChangePassword(mu.ResetPassword(), password);

            ActivityLog x = new ActivityLog();
            x.ObjectUser = userName;
            x.SubjectUser = HttpContext.Current.User.Identity.Name;
            x.ActivityLogTypeId = 2; // 2 : Reset Password
            x.ActivityDate = DateTime.Now;

            of.ActivityLogs.InsertOnSubmit(x);
            of.SubmitChanges();

            ASPxGridView1.CancelEdit();
        }
 partial void DeleteActivityLog(ActivityLog instance);
 partial void UpdateActivityLog(ActivityLog instance);
 partial void InsertActivityLog(ActivityLog instance);