public List<RoleInfo> GetAllRolesDDL() { RoleInfo entItem = new RoleInfo() { IdRole = -1, Name = "Selecciona..." }; List<RoleInfo> entList = GetAllRoles(); entList.Insert(0, entItem); return entList; }
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; }
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; }
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; }
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 }; }
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; }
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; }