public static async Task SetPrivilegedAccess(string login, IEnumerable <PrivilegedAccess> lista)
        {
            using (SMEManagementContextData db = new SMEManagementContextData())
            {
                var listaBanco = db.PrivilegedAccess.Where(x => x.Login.Equals(login));

                var listaDeletar = listaBanco.Where(x => !lista.Any(y => y.OccupationPlaceCode == x.OccupationPlaceCode));

                var listaAdicionar = lista.Where(x => !listaBanco.Any(y => y.OccupationPlaceCode == x.OccupationPlaceCode));

                if (!listaDeletar.Any() && !listaAdicionar.Any())
                {
                    return;
                }

                if (listaDeletar.Any())
                {
                    foreach (var deletar in listaDeletar)
                    {
                        db.PrivilegedAccess.Remove(deletar);
                    }
                }

                if (listaAdicionar.Any())
                {
                    foreach (var adicionar in listaAdicionar)
                    {
                        db.PrivilegedAccess.Add(adicionar);
                    }
                }

                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 2
0
        public async Task SalvarSondagemMatematica(IEnumerable <AlunoSondagemMatematicaDto> alunoSondagemMatematicaDto)
        {
            if (alunoSondagemMatematicaDto == null || !alunoSondagemMatematicaDto.Any())
            {
                throw new Exception("É necessário realizar a sondagem de pelo menos 1 aluno");
            }
            try
            {
                var periodosRespostas = new List <string>();
                var perguntaId        = await ObterPeriodosDasRespostasEhPerguntaDaSondagem(alunoSondagemMatematicaDto, periodosRespostas);

                var listaIdPeriodos = periodosRespostas.Distinct();
                var filtroSondagem  = CriaFiltroListagemMatematica(alunoSondagemMatematicaDto, perguntaId);



                foreach (var periodoId in listaIdPeriodos)
                {
                    using (var contexto = new SMEManagementContextData())
                    {
                        var sondagem = await ObterSondagemAutoralMatematicaPorPeriodo(filtroSondagem, periodoId, contexto);

                        if (sondagem != null)
                        {
                            foreach (var aluno in alunoSondagemMatematicaDto)
                            {
                                AdicionaOUAlteraAlunosERespostas(contexto, sondagem, aluno);
                            }
                            contexto.Sondagem.Update(sondagem);
                            await contexto.SaveChangesAsync();
                        }

                        else
                        {
                            var novaSondagem = CriaNovaSondagem(alunoSondagemMatematicaDto, periodoId, filtroSondagem);
                            contexto.Sondagem.Add(novaSondagem);
                            await contexto.SaveChangesAsync();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static async Task DeleteRole(UserRole role)
 {
     using (SMEManagementContextData db = new SMEManagementContextData())
     {
         db.UserRoles.Remove(role);
         await db.SaveChangesAsync();
     }
 }
Ejemplo n.º 4
0
        public async Task SalvarSondagem(IEnumerable <AlunoSondagemMatematicaDto> alunoSondagemMatematicaDto)
        {
            if (alunoSondagemMatematicaDto == null || !alunoSondagemMatematicaDto.Any())
            {
                throw new Exception("É necessário realizar a sondagem de pelo menos 1 aluno");
            }
            try
            {
                using (var contexto = new SMEManagementContextData())
                {
                    await SalvarAluno(alunoSondagemMatematicaDto, contexto);

                    await contexto.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static async Task <bool> LogoutUser(string username, string session)
        {
            using (SMEManagementContextData db = new SMEManagementContextData())
            {
                LoggedUser loggedUser = await
                                            (from current in db.LoggedUsers.Include(".User")
                                            where current.User.Name == username &&
                                            current.Session == session
                                            select current).FirstOrDefaultAsync();

                if (loggedUser != null)
                {
                    db.LoggedUsers.Remove(loggedUser);
                    await db.SaveChangesAsync();

                    return(true);
                }

                return(false);
            }
        }
        public static async Task <bool> LoginUser(string username, string session, string refreshToken, DateTime expiresAt)
        {
            using (SMEManagementContextData db = new SMEManagementContextData())
            {
                LoggedUser loggedUser = await
                                            (from current in db.LoggedUsers.Include(".User")
                                            where current.User.Name == username
                                            select current).FirstOrDefaultAsync();

                if (loggedUser == null)
                {
                    User user = await
                                    (from current in db.Users
                                    where current.Name == username
                                    select current).FirstOrDefaultAsync();

                    loggedUser = new LoggedUser()
                    {
                        User         = user,
                        RefreshToken = refreshToken,
                        Session      = session,
                        LastAccess   = DateTime.Now,
                        ExpiresAt    = expiresAt
                    };

                    await db.LoggedUsers.AddAsync(loggedUser);
                }
                else
                {
                    loggedUser.RefreshToken = refreshToken;
                    loggedUser.Session      = session;
                    loggedUser.LastAccess   = DateTime.Now;
                    loggedUser.ExpiresAt    = expiresAt;
                }

                await db.SaveChangesAsync();

                return(true);
            }
        }