Exemplo n.º 1
0
        public async Task <Utilizadores> CreateAsync(Utilizadores entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var utilizador = ctx.Utilizador.Add(new DataModels.Utilizador()
                    {
                        Cc = entity.CC,
                        IdPerfilUtilizador = entity.Id_Perfil_Utilizador,
                        Idade = entity.Idade,
                        Morada = entity.Morada,
                        Nib = entity.NIB,
                        Nome = entity.Nome,
                        Sexo = entity.Sexo == "M" ? 0: 1,
                        Username = entity.Username
                    });

                    ctx.SaveChanges();

                    return new Utilizadores()
                    {
                        CC = utilizador.Entity.Cc,
                        Id_Perfil_Utilizador = utilizador.Entity.IdPerfilUtilizador,
                        Idade = utilizador.Entity.Idade,
                        Morada = utilizador.Entity.Morada,
                        NIB = utilizador.Entity.Nib,
                        Nome = utilizador.Entity.Nome,
                        Sexo = utilizador.Entity.Sexo == 0 ? "M" : "F",
                        Username = utilizador.Entity.Username
                    };
                }
            },
                                  ct));
        }
        public async Task <Profissionais_Saude> UpdateAsync(Profissionais_Saude entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var profissional = ctx.ProfissionaisDeSaude.Find(entity.Id);

                    profissional.IdHospital = entity.Id_Hospital;
                    profissional.IdUtilizador = entity.Id_Utilizador;
                    profissional.Profissao = entity.Profissao;

                    ctx.ProfissionaisDeSaude.Update(profissional);
                    ctx.SaveChanges();

                    return new Profissionais_Saude()
                    {
                        Id_Hospital = profissional.IdHospital.GetValueOrDefault(),
                        Id_Utilizador = profissional.IdUtilizador,
                        Profissao = profissional.Profissao
                    };
                }
            },
                                  ct));
        }
Exemplo n.º 3
0
        public async Task <Internamento> UpdateAsync(Internamento entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var internamento = ctx.Internamento.Find(entity.Id);
                    internamento.DataAlta = entity.Data_Alta.DateTime;
                    internamento.DataInternamento = entity.Data_Internamento.DateTime;
                    internamento.IdDoente = entity.Id_Doente;
                    internamento.IdHospital = entity.Id_Hospital;

                    ctx.Internamento.Update(internamento);
                    ctx.SaveChanges();

                    return new Internamento()
                    {
                        Id = internamento.IdInternamento,
                        Data_Alta = internamento.DataAlta,
                        Data_Internamento = internamento.DataInternamento,
                        Id_Doente = internamento.IdDoente,
                        Id_Hospital = internamento.IdHospital
                    };
                }
            },
                                  ct));
        }
        public async Task <Permissoes> CreateAsync(Permissoes entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var permissao = ctx.Permissoes.Add(new DataModels.Permissoes()
                    {
                        Criar = entity.Criar ? "S" : "N",
                        Eliminar = entity.Eliminar ? "S" : "N",
                        Escrever = entity.Escrever ? "S" : "N",
                        Ler = entity.Ler ? "S" : "N",
                        IdModulo = entity.Id_Modulo,
                        IdPerfilUtilizador = entity.Id_Perfil_Utilizador
                    });

                    ctx.SaveChanges();

                    return new Permissoes()
                    {
                        Criar = permissao.Entity.Criar == "S",
                        Eliminar = permissao.Entity.Eliminar == "S",
                        Escrever = permissao.Entity.Escrever == "S",
                        Ler = permissao.Entity.Ler == "S",
                        Id_Modulo = permissao.Entity.IdModulo,
                        Id_Perfil_Utilizador = permissao.Entity.IdPerfilUtilizador,
                        Id = permissao.Entity.IdPermissao
                    };
                }
            },
                                  ct));
        }
        public async Task <Modulos> UpdateAsync(Modulos entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var modulo = ctx.Modulos.Find(entity.Id);

                    modulo.IdModulos = entity.Id;
                    modulo.Endpoint = entity.EndPoint;
                    modulo.Nome = entity.Nome;

                    ctx.Modulos.Update(modulo);
                    ctx.SaveChanges();

                    return new Modulos()
                    {
                        Id = modulo.IdModulos,
                        EndPoint = modulo.Endpoint,
                        Nome = modulo.Nome
                    };
                }
            },
                                  ct));
        }
Exemplo n.º 6
0
        public async Task <Teste> UpdateAsync(Teste entity, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var teste = ctx.Teste.Find(entity.Id);

                    teste.DataTeste = entity.Data_Teste.DateTime;
                    teste.IdDoente = entity.Id_Doente;
                    teste.IdProfissional = entity.Id_Profissional;
                    teste.TipoTeste = entity.Tipo_Teste;
                    teste.ResultadoTeste = entity.Resultado_Teste;
                    teste.IdTeste = entity.Id;

                    ctx.Teste.Update(teste);
                    ctx.SaveChanges();

                    return new Teste()
                    {
                        Data_Teste = teste.DataTeste,
                        Id_Doente = teste.IdDoente,
                        Id_Profissional = teste.IdProfissional,
                        Tipo_Teste = teste.TipoTeste,
                        Resultado_Teste = teste.ResultadoTeste,
                        Id = teste.IdTeste
                    };
                }
            },
                                  ct));
        }
        public async Task DeleteAsync(Modulos entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var modulo = ctx.Modulos.Find(entity.Id);
                    ctx.Modulos.Remove(modulo);

                    ctx.SaveChanges();
                }
            }, ct);
        }
        public async Task DeleteAsync(Permissoes entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var permissao = ctx.Permissoes.Find(entity.Id);
                    ctx.Permissoes.Remove(permissao);

                    ctx.SaveChanges();
                }
            }, ct);
        }
        public async Task DeleteAsync(Profissionais_Saude entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var profissional = ctx.ProfissionaisDeSaude.Find(entity.Id);
                    ctx.ProfissionaisDeSaude.Remove(profissional);

                    ctx.SaveChanges();
                }
            }, ct);
        }
        public async Task DeleteAsync(Perfil_Utilizador entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var perfil = ctx.PerfilUtilizador.Find(entity.Id);
                    ctx.PerfilUtilizador.Remove(perfil);

                    ctx.SaveChanges();
                }
            }, ct);
        }
Exemplo n.º 11
0
        public async Task DeleteAsync(Internamento entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var internamento = ctx.Internamento.Find(entity.Id);
                    ctx.Internamento.Remove(internamento);

                    ctx.SaveChanges();
                }
            }, ct);
        }
Exemplo n.º 12
0
        public async Task DeleteAsync(Teste entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var teste = ctx.Teste.Find(entity.Id);
                    ctx.Teste.Remove(teste);

                    ctx.SaveChanges();
                }
            }, ct);
        }
Exemplo n.º 13
0
        public async Task DeleteAsync(Hospital entity, CancellationToken ct)
        {
            await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var hospital = ctx.Hospital.Find(entity.Id);
                    ctx.Hospital.Remove(hospital);

                    ctx.SaveChanges();
                }
            }, ct);
        }
 public async Task <ICollection <Perfil_Utilizador> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.PerfilUtilizador.Select(x => new Perfil_Utilizador()
             {
                 Id = x.IdPerfilUtilizador,
                 Nome = x.Nome
             }).ToList();
         }
     }, ct));
 }
Exemplo n.º 15
0
 public async Task <ICollection <Doente> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Doente.Select(x => new Doente()
             {
                 Id = x.IdDoente,
                 Id_Utilizador = x.IdUtilizador,
                 Regiao = x.Regiao
             }).ToList();
         }
     }, ct));
 }
Exemplo n.º 16
0
 public async Task <ICollection <Hospital> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Hospital.Select(x => new Hospital()
             {
                 Id = x.IdHospital,
                 Nome = x.Nome,
                 Distrito = x.Distrito
             }).ToList();
         }
     }, ct));
 }
Exemplo n.º 17
0
 public async Task <ICollection <Modulos> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Modulos.Select(x => new Modulos()
             {
                 Id = x.IdModulos,
                 EndPoint = x.Endpoint,
                 Nome = x.Nome
             }).ToList();
         }
     }, ct));
 }
 public async Task <ICollection <Profissionais_Saude> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.ProfissionaisDeSaude.Select(x => new Profissionais_Saude()
             {
                 Id_Hospital = x.IdHospital.GetValueOrDefault(),
                 Id_Utilizador = x.IdUtilizador,
                 Profissao = x.Profissao
             }).ToList();
         }
     }, ct));
 }
        public async Task <Perfil_Utilizador> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var perfil = ctx.PerfilUtilizador.Find(id);

                    return new Perfil_Utilizador()
                    {
                        Id = perfil.IdPerfilUtilizador,
                        Nome = perfil.Nome
                    };
                }
            }, ct));
        }
Exemplo n.º 20
0
        public async Task <Modulos> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var modulo = ctx.Modulos.Find(id);

                    return new Modulos()
                    {
                        Id = modulo.IdModulos,
                        EndPoint = modulo.Endpoint,
                        Nome = modulo.Nome
                    };
                }
            }, ct));
        }
Exemplo n.º 21
0
 public async Task <ICollection <Internamento> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Internamento.Select(x => new Internamento()
             {
                 Id = x.IdInternamento,
                 Data_Alta = x.DataAlta,
                 Data_Internamento = x.DataInternamento,
                 Id_Doente = x.IdDoente,
                 Id_Hospital = x.IdHospital
             }).ToList();
         }
     }, ct));
 }
Exemplo n.º 22
0
        public async Task <Hospital> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var hospital = ctx.Hospital.Find(id);

                    return new Hospital()
                    {
                        Id = hospital.IdHospital,
                        Nome = hospital.Nome,
                        Distrito = hospital.Distrito
                    };
                }
            }, ct));
        }
        public async Task <Profissionais_Saude> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var profissional = ctx.ProfissionaisDeSaude.Find(id);

                    return new Profissionais_Saude()
                    {
                        Id_Hospital = profissional.IdHospital.GetValueOrDefault(),
                        Id_Utilizador = profissional.IdUtilizador,
                        Profissao = profissional.Profissao
                    };
                }
            }, ct));
        }
Exemplo n.º 24
0
        public async Task <Doente> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var doente = ctx.Doente.Find(id);

                    return new Doente()
                    {
                        Id = doente.IdDoente,
                        Id_Utilizador = doente.IdUtilizador,
                        Regiao = doente.Regiao
                    };
                }
            }, ct));
        }
Exemplo n.º 25
0
 public async Task <ICollection <Teste> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Teste.Select(x => new Teste()
             {
                 Data_Teste = x.DataTeste,
                 Id_Doente = x.IdDoente,
                 Id_Profissional = x.IdProfissional,
                 Tipo_Teste = x.TipoTeste,
                 Resultado_Teste = x.ResultadoTeste,
                 Id = x.IdTeste
             }).ToList();
         }
     }, ct));
 }
 public async Task <ICollection <Permissoes> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Permissoes.Select(x => new Permissoes()
             {
                 Criar = x.Criar == "S",
                 Eliminar = x.Eliminar == "S",
                 Escrever = x.Escrever == "S",
                 Ler = x.Ler == "S",
                 Id_Modulo = x.IdModulo,
                 Id_Perfil_Utilizador = x.IdPerfilUtilizador,
                 Id = x.IdPermissao
             }).ToList();
         }
     }, ct));
 }
Exemplo n.º 27
0
        public async Task <Internamento> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var internamento = ctx.Internamento.Find(id);

                    return new Internamento()
                    {
                        Id = internamento.IdInternamento,
                        Data_Alta = internamento.DataAlta,
                        Data_Internamento = internamento.DataInternamento,
                        Id_Doente = internamento.IdDoente,
                        Id_Hospital = internamento.IdHospital
                    };
                }
            }, ct));
        }
Exemplo n.º 28
0
        public async Task <Teste> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var teste = ctx.Teste.Find(id);

                    return new Teste()
                    {
                        Data_Teste = teste.DataTeste,
                        Id_Doente = teste.IdDoente,
                        Id_Profissional = teste.IdProfissional,
                        Tipo_Teste = teste.TipoTeste,
                        Resultado_Teste = teste.ResultadoTeste,
                        Id = teste.IdTeste
                    };
                }
            }, ct));
        }
Exemplo n.º 29
0
 public async Task <ICollection <Utilizadores> > GetAllAsync(CancellationToken ct)
 {
     return(await Task.Run(() =>
     {
         using (var ctx = new DataModels.DatabaseContext())
         {
             return ctx.Utilizador.Select(x => new Utilizadores()
             {
                 CC = x.Cc,
                 Id_Perfil_Utilizador = x.IdPerfilUtilizador,
                 Idade = x.Idade,
                 Morada = x.Morada,
                 NIB = x.Nib,
                 Nome = x.Nome,
                 Sexo = x.Sexo == 0 ? "M" : "F",
                 Username = x.Username
             }).ToList();
         }
     }, ct));
 }
        public async Task <Permissoes> GetAsync(int id, CancellationToken ct)
        {
            return(await Task.Run(() =>
            {
                using (var ctx = new DataModels.DatabaseContext())
                {
                    var permissao = ctx.Permissoes.Find(id);

                    return new Permissoes()
                    {
                        Criar = permissao.Criar == "S",
                        Eliminar = permissao.Eliminar == "S",
                        Escrever = permissao.Escrever == "S",
                        Ler = permissao.Ler == "S",
                        Id_Modulo = permissao.IdModulo,
                        Id_Perfil_Utilizador = permissao.IdPerfilUtilizador,
                        Id = permissao.IdPermissao
                    };
                }
            }, ct));
        }