Exemplo n.º 1
0
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Add(tblRole_User Role_UserObj)
        {
            Role_UserObj.ID = System.Guid.NewGuid();
            int counts = 0;
            //插入数据
            try
            {
                using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
                {
                    MWDB.tblRole_User.AddObject(Role_UserObj);
                    counts = MWDB.SaveChanges();
                    if (counts > 0)
                    {
                        string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                        DbLoggerBLL.SysLogger.Info("Increase user and role relationship successfully! User and role relationship ID: '"
                            + Role_UserObj.ID + "'. User host address: '" + userHostAddress + "' . ");
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                DbLoggerBLL.SysLogger.Error("Increase user and role relationship failed! User and role relationship ID: '"
                    + Role_UserObj.ID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                return false;
            }

            return false;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 新增数据
 /// </summary>
 /// <param name="RoleObj"></param>
 /// <returns></returns>
 public bool Add(tblMenu_Permission_Role tblMenu_Permission_RoleObj)
 {
     tblMenu_Permission_RoleObj.ID = System.Guid.NewGuid();
     string userHostAddress = HttpContext.Current.Request.UserHostAddress;
     int counts = 0;
     //插入数据
     try
     {
         using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
         {
             MWDB.tblMenu_Permission_Role.AddObject(tblMenu_Permission_RoleObj);
             counts = MWDB.SaveChanges();
             if (counts > 0)
             {
                 DbLoggerBLL.SysLogger.Info("Increase menu and the role relationship successfully! ID: '"
                     + tblMenu_Permission_RoleObj.ID + "'. User host address: '"+ userHostAddress + "'");
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         DbLoggerBLL.SysLogger.Error("Increase menu and the role relationship failed! ID: '"
             + tblMenu_Permission_RoleObj.ID + "'. User host address: '" + userHostAddress + "' . Exception info"
             + ex.Message);
         return false;
     }
     return false;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Add(tblUser RoleObj)
        {
            //RoleObj.UserID = System.Guid.NewGuid();
            //获取当前登录用户的ID(Cookies)
            string strUserID = HttpContext.Current.User.Identity.Name;
            if (strUserID == string.Empty || strUserID == null)
            {
                return false;
            }
            System.Guid guidUserID = new Guid(strUserID);

            RoleObj.SendEmail = true;
            RoleObj.LastModifiedByID = guidUserID;
            RoleObj.CreatedByID = guidUserID;
            RoleObj.OwnerID = guidUserID;
            RoleObj.CreatedDate = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.LastModifiedDate = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.SystemModstamp = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.IsDeleted = false;
            RoleObj.Avatar = this.GetImageIo();
            int counts = 0;
            //插入数据
            try
            {
                MWDatabaseEntities MWDB = new MWDatabaseEntities();
                MWDB.tblUser.AddObject(RoleObj);
                counts = MWDB.SaveChanges();
                if (counts > 0)
                {
                    string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                    DbLoggerBLL.SysLogger.Info("Increase user successfully! User id: '"
                        + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. ");
                    return true;
                }
            }
            catch (Exception ex)
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                DbLoggerBLL.SysLogger.Error("Increase user failed! User id: '"
                    + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. Exception info:" + ex.Message);
                return false;
            }

            return false;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 新增数据
 /// </summary>
 /// <param name="RoleObj"></param>
 /// <returns></returns>
 public bool Add(tblRole RoleObj)
 {
     //获取当前登录用户的ID(Cookies)
     string strUserID = HttpContext.Current.User.Identity.Name;
     if (string.IsNullOrEmpty(strUserID))
     {
         FormsAuthentication.RedirectToLoginPage();
         return false;
     }
     System.Guid guidUserID = new Guid(strUserID);
     RoleObj.RoleID = System.Guid.NewGuid();
     RoleObj.LastModifiedByID = guidUserID;
     RoleObj.CreatedByID = guidUserID;
     RoleObj.OwnerID = guidUserID;
     RoleObj.CreatedDate = Convert.ToDateTime(System.DateTime.Now);
     RoleObj.LastModifiedDate = Convert.ToDateTime(System.DateTime.Now);
     RoleObj.SystemModstamp = Convert.ToDateTime(System.DateTime.Now);
     RoleObj.IsDeleted = false;
     int counts = 0;
     //插入数据
     try
     {
         using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
         {
             MWDB.tblRole.AddObject(RoleObj);
             counts = MWDB.SaveChanges();
             if (counts > 0)
             {
                 string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                 DbLoggerBLL.SysLogger.Info("Increase role info successfully! Role ID: '"
                     + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "'");
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         string userHostAddress = HttpContext.Current.Request.UserHostAddress;
         DbLoggerBLL.SysLogger.Error("Increase role info failed! Role ID: '"
             + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "' . Exception info:"+ ex.Message);
         return false;
     }
     return false;
 }
Exemplo n.º 5
0
 /// <summary>
 /// 删除一条数据
 /// </summary>
 public int DeleteT(string ID)
 {
     string userHostAddress = HttpContext.Current.Request.UserHostAddress;
     int count = 0;
     using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
     {
         try
         {
             System.Guid gu = new Guid(ID);
             tblRole objRole = MWDB.tblRole.First(r => r.RoleID == gu);
             if (objRole != null)
             {
                 List<tblMenu_Permission_Role> list = MWDB.tblMenu_Permission_Role.Where<tblMenu_Permission_Role>(m => m.RoleID == gu).ToList();
                 if (list.Count > 0)
                 {
                     foreach (var lists in list)
                     {
                         tblMenu_Permission_Role tblMenu_Permission_RoleObj;
                         tblMenu_Permission_RoleObj = MWDB.tblMenu_Permission_Role.First(m => m.RoleID == lists.RoleID);
                         MWDB.DeleteObject(tblMenu_Permission_RoleObj);
                         count = MWDB.SaveChanges();
                         if (count>0)
                         {
                             DbLoggerBLL.SysLogger.Info("Delete menu and the role relationship successfully! ID: '"
                                 + tblMenu_Permission_RoleObj.ID + "'. User host address: '" + userHostAddress + "'");
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             DbLoggerBLL.SysLogger.Error("Delete menu and the role relationship failed! ID: '"
                     + ID + "'. User host address: '" + userHostAddress + "' . Exception info"
                     + ex.Message);
         }
     }
     return count;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="KeyId">需要删除对象的ID</param>
        /// <returns>返回受影响的行数</returns>
        public bool Delete(string strKeyId)
        {
            //影响行数标记
            int counts = 0;

            //转换成Guid类型
            System.Guid KeyIdGuid = new Guid(strKeyId);

            //需要跟新的对象
            tblRole_User tblRole_Users;

            try
            {
                using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
                {
                    tblRole_Users = MWDB.tblRole_User.FirstOrDefault(t => t.UserID == KeyIdGuid);
                    if (tblRole_Users != null)
                    {
                        MWDB.DeleteObject(tblRole_Users);
                        counts = MWDB.SaveChanges();
                    }
                    if (counts > 0)
                    {
                        string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                        DbLoggerBLL.SysLogger.Info("Delete user and role relationship successfully! User and role relationship ID: '"
                            + strKeyId + "'. User host address: '" + userHostAddress + "' . ");
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                DbLoggerBLL.SysLogger.Error("Increase user and role relationship failed! User and role relationship ID: '"
                    + strKeyId + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                return false;
            }
            return false;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Update(tblUser UserNew)
        {
            tblUser UserOld;
            int counts = 0;//影响行数标记
            using (MWDatabaseEntities MWDB =new MWDatabaseEntities())
            {
                try
                {
                    UserOld = MWDB.tblUser.FirstOrDefault(t => t.UserID == UserNew.UserID);

                    //更新数据字段
                    UserOld.UserName = UserNew.UserName;
                    UserOld.LoginName = UserNew.LoginName;
                    UserOld.LoginPwd = UserNew.LoginPwd;
                    UserOld.UserCode = UserNew.UserCode;
                    UserOld.State = UserNew.State;
                    UserOld.Email = UserNew.Email;
                    UserOld.Desc = UserNew.Desc;
                    UserOld.Avatar = UserNew.Avatar;
                    //获取当前登录用户的ID(Cookies)
                    string strUserID = HttpContext.Current.User.Identity.Name;
                    if (string.IsNullOrEmpty(strUserID))
                    {
                        FormsAuthentication.RedirectToLoginPage();
                        return false;
                    }

                    UserOld.LastModifiedByID = new Guid(strUserID);
                    DateTime dates = System.DateTime.Now;
                    UserOld.LastModifiedDate = dates;
                    UserOld.SystemModstamp = dates;

                    ObjectStateEntry ose = MWDB.ObjectStateManager.GetObjectStateEntry(UserOld);
                    IEnumerable<string> list = ose.GetModifiedProperties();
                    string logBody = string.Empty;
                    foreach (string pr in list)
                    {
                        string strs = pr;//更新实体的属性名
                        string strNew = ose.CurrentValues[strs].ToString();
                        string strOld = ose.OriginalValues[strs].ToString();
                        if (strNew != strOld)
                        {
                            strNew = string.IsNullOrEmpty(strNew) ? "null" : strNew;//如果字符串为空,则将null赋给字符串
                            strOld = string.IsNullOrEmpty(strOld) ? "null" : strOld;
                            switch (strs)
                            {
                                case "LastModifiedByID":
                                    //系统字段不进行发送
                                    break;
                                case "LastModifiedDate":
                                    //系统字段不进行发送
                                    break;
                                case "SystemModstamp":
                                    //系统字段不进行发送
                                    break;
                                default:
                                    logBody += ", " + strs + ": '" + strOld + "'" + " had been changed '" + strNew + "'";
                                    break;
                            }
                        }
                    }

                    counts = MWDB.SaveChanges();
                    if (counts > 0)
                    {
                        string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                        DbLoggerBLL.SysLogger.Info("Update user info failed! User update log: '"
                            + logBody + "'. User host address: '" + userHostAddress + "' .");
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                    DbLoggerBLL.SysLogger.Error("Update user info failed! User id: '"
                            + UserNew.UserID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                    return false;
                }
            }
            return false;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="KeyId">需要删除对象的ID</param>
        /// <returns>返回受影响的行数</returns>
        public bool Delete(string strKeyId)
        {
            //影响行数标记
            int counts = 0;

            //转换成Guid类型
            System.Guid KeyIdGuid = new Guid(strKeyId);

            //需要跟新的对象
            tblRole tblRoles;

            try
            {
                using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
                {
                    tblRoles = MWDB.tblRole.First(t => t.RoleID == KeyIdGuid);
                    tblRoles.IsDeleted = true;
                    counts = MWDB.SaveChanges();
                    if (counts > 0)
                    {
                        string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                        DbLoggerBLL.SysLogger.Info("Delete role successfully! Role ID: '"
                            + strKeyId + "'. User host address: '" + userHostAddress + "' . ");
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                DbLoggerBLL.SysLogger.Error("Delete role failed! Role ID: '"
                    + strKeyId + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                return false;
            }
            return false;
        }