예제 #1
0
        public List<RoleInfo> GetAllRolesDDL()
        {
            RoleInfo entItem = new RoleInfo() { IdRole = -1, Name = "Selecciona..." };

            List<RoleInfo> entList = GetAllRoles();

            entList.Insert(0, entItem);
            return entList;
        }
예제 #2
0
        public List<RoleInfo> GetAllRoles()
        {
            TCRepositoryDataContext context = DataBaseUtils.GetContext();
            List<tbl_Roles> dbListRoles = context.tbl_Roles.ToList();
            List<RoleInfo> entList = new List<RoleInfo>();
            foreach (var drItem in dbListRoles)
            {
                RoleInfo entItem = new RoleInfo();
                AssignDataObjectToEntity(drItem, ref entItem);
                entList.Add(entItem);
            }

            return entList;
        }
예제 #3
0
        public RoleInfo GetRoleByUserID(int IdUser)
        {
            TCRepositoryDataContext context = DataBaseUtils.GetContext();
            tbl_Roles dbRole = (from r in context.tbl_Roles
                                join u in context.tbl_Users on r.IdRole equals u.IdRole
                                where u.IdUser == IdUser
                                select r).FirstOrDefault();

            RoleInfo entItem = new RoleInfo();
            if (dbRole!=null)
            {
                AssignDataObjectToEntity(dbRole, ref entItem);
            }
            return entItem;
        }
예제 #4
0
        private bool UpdateRole(RoleInfo entRole)
        {
            DbTransaction trans = null;
            TCRepositoryDataContext context = DataBaseUtils.GetContext();
            bool result = false;

            try
            {
                context.Connection.Open();
                trans = context.Connection.BeginTransaction();
                context.Transaction = trans;

                tbl_Roles dbRole = context.tbl_Roles.Where(s => s.IdRole == entRole.IdRole).FirstOrDefault();
                dbRole.IdStatus = entRole.EntStatus.IdStatus;
                dbRole.Name = entRole.Name;
                dbRole.Description = entRole.Description;
                dbRole.RoleCode = entRole.RoleCode;
                context.SubmitChanges();

                List<tbl_Roles_SiteMap> listRolesSiteMap = context.tbl_Roles_SiteMap.Where(rs => rs.IdRole == entRole.IdRole).ToList();
                context.tbl_Roles_SiteMap.DeleteAllOnSubmit(listRolesSiteMap);
                context.SubmitChanges();

                List<ServicesLibrary.Entities.SiteMap> listSiteMap = entRole.EntListSiteMap;
                List<tbl_Roles_SiteMap> dbRolesSiteMap = (from s in listSiteMap
                                                          select new tbl_Roles_SiteMap()
                                                          {
                                                              IdRole = dbRole.IdRole,
                                                              IdSiteMap = s.IdSiteMap
                                                          }).ToList();
                context.tbl_Roles_SiteMap.InsertAllOnSubmit(dbRolesSiteMap);
                context.SubmitChanges();

                trans.Commit();
                result = true;

            }
            catch (SqlException excs)
            {
                if (trans != null)
                    trans.Rollback();

            }
            catch (Exception exc)
            {
                if (trans != null)
                    trans.Rollback();
            }
            finally
            {
                if (context.Connection.State == ConnectionState.Open)
                    context.Connection.Close();
            }
            return result;
        }
예제 #5
0
 private void AssignDataObjectToEntity(tbl_Roles dbRole, ref RoleInfo entRoleInfo)
 {
     entRoleInfo.IdRole = dbRole.IdRole;
     entRoleInfo.Name = dbRole.Name;
     entRoleInfo.Description = dbRole.Description;
     entRoleInfo.RoleCode = dbRole.RoleCode;
     entRoleInfo.EntStatus = new Status { IdStatus = dbRole.tbl_Status.IdStatus, Name = dbRole.tbl_Status.Name };
 }
예제 #6
0
        public bool Save(RoleInfo newRoleInfo, Dictionary<int, int> RoleSiteMap)
        {
            bool blResult = false;
            try {

                if (newRoleInfo.IdRole == 0)
                {
                    blResult = InsertRole(newRoleInfo);
                }
                else
                {
                    blResult = UpdateRole(newRoleInfo);
                }
                //if (blResult)
                //{
                //    blResult = mscConnector.ExecuteNoNQuery(rqQuery.DeleteRoleSiteMapById(newRoleInfo.IdRole));
                //    foreach (KeyValuePair<int, int> KeyRoleSiteMap in RoleSiteMap)
                //    {
                //        blResult = mscConnector.ExecuteNoNQuery(rqQuery.Insert(KeyRoleSiteMap,newRoleInfo.IdRole));
                //    }
                //}
            }
            catch { return false; }
            return blResult;
        }
예제 #7
0
        public bool Save(RoleInfo newRoleInfo)
        {
            bool blResult = false;
            try
            {

                if (newRoleInfo.IdRole == 0)
                {
                    blResult = InsertRole(newRoleInfo);
                    //int IdRole = mscConnector.GetLastID(rqQuery.GetLastId(), rqQuery.IdField);
                    //newRoleInfo.IdRole = IdRole;
                }
                else
                {
                    blResult = UpdateRole(newRoleInfo);
                }
            }
            catch { return false; }
            return blResult;
        }