Ejemplo n.º 1
0
        public ActionResult <ModifyUserDto> GetById()
        {
            var userId = GetIdUser();
            var user   = _context.Users
                         .Include(x => x.Distribution)
                         .FirstOrDefault(j => j.Id == userId);

            if (user == null)
            {
                return(null);
            }
            ModifyUserDto modifyUserDto = new ModifyUserDto
            {
                Dni            = user.Dni,
                UserName       = user.UserName,
                PhoneNumber    = user.PhoneNumber,
                FirstName      = user.FirstName,
                LastName       = user.LastName,
                DistributionId = user.DistributionId,
                OrganismId     = user.Distribution.OrganismId
            };

            var RolesUser = _context.UserRoles.ToList();
            var AllRoles  = _context.Roles.ToList();

            List <RoleWhenModifyUser> ListRolesBelongsToUser = new List <RoleWhenModifyUser>();

            foreach (var role in AllRoles)
            {
                if (RolesUser.Exists(x => x.UserId == user.Id && x.RoleId == role.Id))
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id            = role.Id,
                        Name          = role.Name,
                        RolBelongUser = true
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
                else
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id            = role.Id,
                        Name          = role.Name,
                        RolBelongUser = false
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
            }
            modifyUserDto.RolesUser = ListRolesBelongsToUser;
            return(modifyUserDto);
        }
Ejemplo n.º 2
0
        public ActionResult <ModifyUserDto> GetById(Guid id)
        {
            var user = _context.Users.Find(id);

            if (user == null)
            {
                return(null);
            }
            ModifyUserDto modifyUserDto = new ModifyUserDto
            {
                Dni         = user.Dni,
                UserName    = user.UserName,
                PhoneNumber = user.PhoneNumber,
            };

            var RolesUser = _context.UserRoles.ToList();
            var AllRoles  = _context.Roles.ToList();

            List <RoleWhenModifyUser> ListRolesBelongsToUser = new List <RoleWhenModifyUser>();

            foreach (var role in AllRoles)
            {
                if (RolesUser.Exists(x => x.UserId == user.Id && x.RoleId == role.Id))
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id            = role.Id,
                        Name          = role.Name,
                        RolBelongUser = true
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
                else
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id            = role.Id,
                        Name          = role.Name,
                        RolBelongUser = false
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
            }
            modifyUserDto.RolesUser = ListRolesBelongsToUser;
            return(modifyUserDto);
        }
Ejemplo n.º 3
0
        public ActionResult <ModifyUserDto> GetById(Guid id)
        {
            var user = _context.Users.Find(id);

            if (user == null)
            {
                return(null);
            }

            var supervisorId           = _context.SupervisorUserAgents.FirstOrDefault(x => x.AgentId == user.Id);
            var supervisorId1Nulleable = supervisorId == null ? Guid.Empty : supervisorId.SupervisorId;
            var supervisorId2Nulleable = supervisorId == null ? Guid.Empty : supervisorId.SupervisorId2;

            ModifyUserDto modifyUserDto = new ModifyUserDto
            {
                Dni                = user.Dni,
                UserName           = user.UserName,
                PhoneNumber        = user.PhoneNumber,
                FirstName          = user.FirstName,
                LastName           = user.LastName,
                DistributionId     = user.DistributionId,
                CategoryId         = user.CategoryId,
                SupervisorAgentId  = supervisorId1Nulleable == null ? Guid.Empty : supervisorId1Nulleable,
                SupervisorAgentId2 = supervisorId2Nulleable == null ? Guid.Empty : supervisorId2Nulleable
            };

            var RolesUser = _context.UserRoles.ToList();
            var AllRoles  = _context.Roles.ToList();

            List <RoleWhenModifyUser> ListRolesBelongsToUser = new List <RoleWhenModifyUser>();

            foreach (var role in AllRoles)
            {
                if (RolesUser.Exists(x => x.UserId == user.Id && x.RoleId == role.Id))
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id             = role.Id,
                        Name           = role.Name,
                        NormalizedName = role.NormalizedName,
                        RolBelongUser  = true
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
                else
                {
                    RoleWhenModifyUser roleWhenModifyUser = new RoleWhenModifyUser
                    {
                        Id             = role.Id,
                        Name           = role.Name,
                        NormalizedName = role.NormalizedName,
                        RolBelongUser  = false
                    };

                    ListRolesBelongsToUser.Add(roleWhenModifyUser);
                }
            }
            modifyUserDto.RolesUser = ListRolesBelongsToUser;
            return(modifyUserDto);
        }