Exemplo n.º 1
0
        public virtual void UpdateScreenPermissions(UpdateScreenPermissionParam updates)
        {
            using (SecurityEntities db = new SecurityEntities())
                using (TransactionScope trans = new TransactionScope())
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var g in updates.out_GroupPermissions)
                    {
                        sb.Append(tbs_PermissionGroupMap.GetSqlDelete(g.AcResourceName, g.GroupCode, g.PermissionCode));
                        sb.AppendLine(";");
                    }
                    foreach (var g in updates.in_GroupPermissions)
                    {
                        sb.Append(tbs_PermissionGroupMap.GetSqlDelete(g.AcResourceName, g.GroupCode, g.PermissionCode));
                        sb.AppendLine(";");
                    }
                    foreach (var u in updates.out_UserPermissions)
                    {
                        sb.Append(tbs_PermissionUserMap.GetSqlDelete(u.AcResourceName, u.UserCode, u.PermissionCode));
                        sb.Append(";");
                    }
                    foreach (var u in updates.in_UserPermissions)
                    {
                        sb.Append(tbs_PermissionUserMap.GetSqlDelete(u.AcResourceName, u.UserCode, u.PermissionCode));
                        sb.Append(";");
                    }
                    string sql = sb.ToString();
                    if (false == string.IsNullOrEmpty(sql))
                    {
                        db.Database.ExecuteSqlCommand(sql);
                    }

                    foreach (var g in updates.in_GroupPermissions)
                    {
                        db.tbs_PermissionGroupMap.Add(
                            new tbs_PermissionGroupMap
                        {
                            AcResourceName = g.AcResourceName,
                            GroupCode      = g.GroupCode,
                            PermissionCode = g.PermissionCode,
                        });
                        db.SaveChanges();
                    }
                    foreach (var g in updates.in_UserPermissions)
                    {
                        db.tbs_PermissionUserMap.Add(
                            new tbs_PermissionUserMap
                        {
                            AcResourceName = g.AcResourceName,
                            UserCode       = g.UserCode,
                            PermissionCode = g.PermissionCode,
                        });
                        db.SaveChanges();
                    }

                    trans.Complete();
                }
        }
Exemplo n.º 2
0
        public virtual void UpdateGroupMember(UpdateGroupMemberParam updates)
        {
            using (SecurityEntities sc = new SecurityEntities())
                using (TransactionScope ts = new TransactionScope())
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var m in updates.out_Members)
                    {
                        sb.Append(tbs_UserGroup.GetSqlDelete(m.UserCode, m.GroupCode));
                        sb.AppendLine(";");
                    }
                    foreach (var m in updates.in_Members)
                    {
                        sb.Append(tbs_UserGroup.GetSqlDelete(m.UserCode, m.GroupCode));
                        sb.AppendLine(";");
                    }
                    string sql = sb.ToString();
                    if (false == string.IsNullOrEmpty(sql))
                    {
                        sc.Database.ExecuteSqlCommand(sql);
                    }

                    foreach (var m in updates.in_Members)
                    {
                        sc.tbs_UserGroup.Add(
                            new tbs_UserGroup
                        {
                            GroupCode = m.GroupCode,
                            UserCode  = m.UserCode,
                        });
                        sc.SaveChanges();
                    }
                    ts.Complete();
                }
        }
Exemplo n.º 3
0
 public virtual void CreateGroup(tbs_Group group)
 {
     using (SecurityEntities sc = new SecurityEntities())
         using (TransactionScope ts = new TransactionScope())
         {
             var       mapper   = ServiceContainer.GetService <IMapper>();
             tbs_Group newGroup = mapper.Map <tbs_Group>(group);
             sc.tbs_Group.Add(newGroup);
             sc.SaveChanges();
             ts.Complete();
         }
 }
Exemplo n.º 4
0
 public virtual void CreateUser(tbs_User user)
 {
     using (SecurityEntities sc = new SecurityEntities())
         using (TransactionScope ts = new TransactionScope())
         {
             var      mapper  = ServiceContainer.GetService <IMapper>();
             tbs_User newUser = mapper.Map <tbs_User>(user);
             newUser.Password = SecurityModelCrypto.HashEncrypt(user.Password);
             sc.tbs_User.Add(newUser);
             sc.SaveChanges();
             ts.Complete();
         }
 }
Exemplo n.º 5
0
 public virtual void UpdateGroup(tbs_Group group)
 {
     using (SecurityEntities sc = new SecurityEntities())
         using (TransactionScope ts = new TransactionScope())
         {
             var       mapper = ServiceContainer.GetService <IMapper>();
             tbs_Group edited = mapper.Map <tbs_Group>(group);
             sc.tbs_Group.Attach(edited);
             sc.Entry(edited).State = System.Data.Entity.EntityState.Modified;
             sc.SaveChanges();
             ts.Complete();
         }
 }
Exemplo n.º 6
0
        public virtual void UpdateUser(tbs_User user)
        {
            using (SecurityEntities sc = new SecurityEntities())
                using (TransactionScope ts = new TransactionScope())
                {
                    var mapper = ServiceContainer.GetService <IMapper>();

                    var      passList = sc.tbs_User.Where(u => u.UserCode == user.UserCode).Select(u => u.Password).ToList();
                    string   pass     = passList.Count > 0 ? passList[0] : string.Empty;
                    tbs_User edited   = mapper.Map <tbs_User>(user);
                    if (false == edited.Password.Equals(pass) || string.IsNullOrEmpty(pass))
                    {
                        edited.Password = SecurityModelCrypto.HashEncrypt(edited.Password);
                    }

                    sc.tbs_User.Attach(edited);
                    sc.Entry(edited).State = System.Data.Entity.EntityState.Modified;
                    sc.SaveChanges();
                    ts.Complete();
                }
        }
Exemplo n.º 7
0
        public virtual bool ChangePassword(string userCode, string oldPassword, string newPassword)
        {
            using (SecurityEntities db = new SecurityEntities())
            {
                string encryptedOld = SecurityModelCrypto.HashEncrypt(oldPassword);
                var    users        = db.tbs_User
                                      .Where(a => (a.UserCode == userCode) &&
                                             a.Password == encryptedOld)
                                      .ToList();
                if (users.Count != 1)
                {
                    return(false);
                }

                string encryptedNew = SecurityModelCrypto.HashEncrypt(newPassword);
                users[0].Password        = encryptedNew;
                db.Entry(users[0]).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                return(true);
            }
        }