Esempio n. 1
0
        public async Task <Object> Add(RhNetContext rhNetContext, EntidadeModel entidadeModel)
        {
            Entidade entidade = new Entidade()
            {
                Codigo_Audesp = entidadeModel.Codigo_Audesp,
                Descricao     = entidadeModel.Descricao
            };

            if (entidadeModel.Municipio_Id.HasValue)
            {
                Municipio municipio = await rhNetContext.Municipios.FindAsync(entidadeModel.Municipio_Id);

                if (municipio != null)
                {
                    entidade.Municipio = municipio;
                    entidadeModel.Municipio_Descricao = municipio.Descricao;
                }
            }
            try
            {
                rhNetContext.Entry(entidade).State = EntityState.Added;
                await rhNetContext.SaveChangesAsync();

                await rhNetContext.Entry(entidade).ReloadAsync();

                entidadeModel.Id = entidade.Id;

                return(entidadeModel);
            }
            catch (DbUpdateException ex)
            {
                return(ex.InnerException.ToString());
            }
        }
Esempio n. 2
0
        public async Task <Object> AddFavorite(RhNetContext context, string userName, FavoriteModel favoriteModel)
        {
            string userId = await(from x in context.Users
                                  where x.UserName == userName
                                  select x.Id).FirstOrDefaultAsync();

            if (string.IsNullOrEmpty(userId))
            {
                return("Usuário não encontrado");
            }
            ApplicationMenu menu = await(from x in context.ApplicationMenus
                                         where x.Path == favoriteModel.Path && x.Role_Name == favoriteModel.Profile
                                         select x).FirstOrDefaultAsync();

            if (menu == null)
            {
                return("Menu não encontrado");
            }

            Favorite favorite = new Favorite();

            favorite.UserId = userId;
            favorite.MenuId = menu.Id;
            context.Entry(favorite).State = EntityState.Added;
            await context.SaveChangesAsync();

            favoriteModel.Header = menu.Header;
            return(favoriteModel);
        }
Esempio n. 3
0
 public async Task <Boolean> IsFavorite(RhNetContext context, string userName, string path, string profile)
 {
     return(await(from x in context.Favorites
                  from y in context.ApplicationMenus.Where(e => e.Id == x.MenuId)
                  from z in context.Users.Where(e => e.Id == x.UserId)
                  where y.Path == path && z.UserName == userName && y.Role_Name == profile
                  select x.Id).CountAsync() > 0);
 }
Esempio n. 4
0
        public async Task <MenuModel> RemoveMenu(MenuModel menuModel, RhNetContext context)
        {
            ApplicationMenu menu = await context.ApplicationMenus.FindAsync(menuModel.Id);

            context.Entry(menu).State = EntityState.Deleted;
            await context.SaveChangesAsync();

            return(menuModel);
        }
Esempio n. 5
0
        public async Task <ClientModel> RemoveClient(ClientModel clientModel, RhNetContext context)
        {
            Client client = await context.Clients.FindAsync(clientModel.Id);

            context.Entry(client).State = EntityState.Deleted;
            await context.SaveChangesAsync();

            return(clientModel);
        }
Esempio n. 6
0
 public async Task <List <QuadroModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Quadros
                  orderby x.Descricao
                  select new QuadroModel()
     {
         Descricao = x.Descricao,
         Id = x.Id
     }).ToListAsync());
 }
Esempio n. 7
0
 public async Task <List <Tipo_de_Ato_NormativoModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Tipos_de_Ato_Normativo
                  orderby x.Descricao
                  select new Tipo_de_Ato_NormativoModel()
     {
         Descricao = x.Descricao,
         Id = x.Id
     }).ToListAsync());
 }
 public async Task <List <PermissionModel> > GetAllPermissions(RhNetContext context)
 {
     return(await(from x in context.Permissions
                  orderby x.Table, x.Description
                  select new PermissionModel()
     {
         Description = x.Description,
         Id = x.Id,
         Table = x.Table
     }).ToListAsync());
 }
 public async Task <List <MunicipioModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Municipios
                  orderby x.Descricao
                  select new MunicipioModel()
     {
         Descricao = x.Descricao,
         Codigo_Audesp = x.Codigo_Audesp,
         Id = x.Id
     }).ToListAsync());
 }
Esempio n. 10
0
 public async Task <ActionResult <PermissionModel> > RemovePermission([FromServices] RhNetContext rhNetContext, [FromBody] PermissionModel permissionModel)
 {
     if (ModelState.IsValid)
     {
         PermissionRepository repository = new PermissionRepository();
         return(await repository.RemovePermission(permissionModel, rhNetContext));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Esempio n. 11
0
 public async Task <ActionResult <ClientModel> > UpdateClient([FromServices] RhNetContext rhNetContext, [FromBody] ClientModel clientModel)
 {
     if (ModelState.IsValid)
     {
         ClientRepository repository = new ClientRepository();
         return(await repository.UpdateClient(clientModel, rhNetContext));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Esempio n. 12
0
 public async Task <ActionResult <MenuModel> > RemoveMenu([FromServices] RhNetContext rhNetContext, [FromBody] MenuModel menuModel)
 {
     if (ModelState.IsValid)
     {
         MenuRepository repository = new MenuRepository();
         return(await repository.RemoveMenu(menuModel, rhNetContext));
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Esempio n. 13
0
        public async Task <ClientModel> UpdateClient(ClientModel clientModel, RhNetContext context)
        {
            Client client = await context.Clients.FindAsync(clientModel.Id);

            client.Description = clientModel.Description;
            client.Cnpj        = clientModel.Cnpj;
            client.Situation   = clientModel.Situation;

            context.Entry(client).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(clientModel);
        }
Esempio n. 14
0
        public async Task <List <ClientModel> > GetAllClients(RhNetContext context)
        {
            return(await(from x in context.Clients
                         select new ClientModel()
            {
                Situation = x.Situation,
                Cnpj = x.Cnpj,
                Description = x.Description,
                Id = x.Id
            }).ToListAsync());

            ;
        }
Esempio n. 15
0
        public async Task <ActionResult> Remove([FromServices] RhNetContext rhNetContext, [FromBody] EntidadeModel entidadeModel)
        {
            EntitadeRepository repository = new EntitadeRepository();
            object             result     = await repository.Remove(rhNetContext, entidadeModel);

            if (result.GetType() == typeof(EntidadeModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Esempio n. 16
0
        public async Task <ActionResult> RemoveFavorite([FromServices] RhNetContext rhNetContext, [FromBody] FavoriteModel favoriteModel)
        {
            FavoriteRepository repository = new FavoriteRepository();
            var result = await repository.RemoveFavorite(rhNetContext, this.User.Identity.Name, favoriteModel);

            if (result == favoriteModel)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Esempio n. 17
0
        public async Task <ActionResult> Remove([FromServices] RhNetContext rhNetContext, [FromBody] SubquadroModel subquadroModel)
        {
            SubquadroRepository repository = new SubquadroRepository();
            object result = await repository.Remove(rhNetContext, subquadroModel);

            if (result.GetType() == typeof(SubquadroModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Esempio n. 18
0
 public async Task <List <EntidadeModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Entidades
                  from y in rhNetContext.Municipios.Where(e => e.Id == x.Municipio_Id).DefaultIfEmpty()
                  orderby x.Descricao
                  select new EntidadeModel()
     {
         Descricao = x.Descricao,
         Codigo_Audesp = x.Codigo_Audesp,
         Id = x.Id,
         Municipio_Id = y.Id,
         Municipio_Descricao = y.Descricao
     }).ToListAsync());
 }
Esempio n. 19
0
        public async Task <List <ClientModel> > GetClientsAsync(RhNetContext rhNetContext, string userId)
        {
            List <ClientModel> clients = await(from x in rhNetContext.UserClients
                                               from y in rhNetContext.Clients.Where(e => e.Id == x.ClientId)
                                               where x.UserId == userId
                                               select new ClientModel()
            {
                Id          = y.Id,
                Cnpj        = y.Cnpj,
                Description = y.Description,
                Situation   = y.Situation
            }).ToListAsync();

            return(clients);
        }
        public async Task <ActionResult> Remove([FromServices] RhNetContext rhNetContext, [FromBody] Tipo_de_Ato_NormativoModel tipo_de_ato_normativoModel)
        {
            Tipo_de_Ato_NormativoRepository repository = new Tipo_de_Ato_NormativoRepository();
            object result = await repository.Remove(rhNetContext, tipo_de_ato_normativoModel);

            if (result.GetType() == typeof(Tipo_de_Ato_NormativoModel))
            {
                return(Ok(result));
            }
            else
            {
                ModelState.AddModelError("errors", result.ToString());
                return(BadRequest(ModelState));
            }
        }
Esempio n. 21
0
        public async Task <MenuModel> UpdateMenu(MenuModel menuModel, RhNetContext context)
        {
            ApplicationMenu menu = await context.ApplicationMenus.FindAsync(menuModel.Id);

            menu.Header          = menuModel.Header;
            menu.Path            = menuModel.Path;
            menu.Permission_Name = menuModel.Permission_Name;
            menu.Role_Name       = menuModel.Role_Name;
            menu.Quick_Access    = menuModel.Quick_Access;

            context.Entry(menu).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(menuModel);
        }
Esempio n. 22
0
        public async Task <List <MenuModel> > GetAllMenus(RhNetContext context)
        {
            return(await(from x in context.ApplicationMenus
                         select new MenuModel()
            {
                Role_Name = x.Role_Name,
                Header = x.Header,
                Id = x.Id,
                Path = x.Path,
                Permission_Name = x.Permission_Name,
                Quick_Access = x.Quick_Access
            }).ToListAsync());

            ;
        }
Esempio n. 23
0
        public async Task <object> RemoveAtoNormativo(RhNetContext rhNetContext, Quadro_Ato_NormativoModel quadro_Ato_NormativoModel)
        {
            Quadro_Ato_Normativo quadro_ato_normativo = await(from x in rhNetContext.Quadros_Atos_Normativos
                                                              where x.Ato_Normativo_Id == quadro_Ato_NormativoModel.Ato_Normativo_Id &&
                                                              x.Quadro_Id == quadro_Ato_NormativoModel.Quadro_Id
                                                              select x).FirstOrDefaultAsync();

            if (quadro_ato_normativo == null)
            {
                return("Ato Normativo não encontrado");
            }

            rhNetContext.Entry(quadro_ato_normativo).State = EntityState.Deleted;
            await rhNetContext.SaveChangesAsync();

            return(quadro_Ato_NormativoModel);
        }
Esempio n. 24
0
 public async Task <List <SubquadroModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Subquadros
                  from y in rhNetContext.Quadros.Where(e => e.Id == x.Quadro_Id)
                  orderby x.Descricao
                  select new SubquadroModel()
     {
         Descricao = x.Descricao,
         Id = x.Id,
         Sigla = x.Sigla,
         Quadro = new QuadroModel()
         {
             Id = y.Id,
             Descricao = y.Descricao
         }
     }).ToListAsync());
 }
 public async Task <List <Ato_NormativoModel> > Get(RhNetContext rhNetContext)
 {
     return(await(from x in rhNetContext.Atos_Normativos
                  from y in rhNetContext.Tipos_de_Ato_Normativo.Where(e => e.Id == x.Tipo_de_Ato_Normativo_Id)
                  orderby x.Descricao
                  select new Ato_NormativoModel()
     {
         Descricao = x.Descricao,
         Id = x.Id,
         Tipo_de_Ato_Normativo_Id = y.Id,
         Tipo_de_Ato_Normativo_Descricao = y.Descricao,
         Ano = x.Ano,
         Numero = x.Numero,
         Publicacao_Data = x.Publicacao_Data,
         Vigencia_Data = x.Vigencia_Data
     }).ToListAsync());
 }
Esempio n. 26
0
        public async Task <ClientModel> AddClient(ClientModel clientModel, RhNetContext context)
        {
            Client client = new Client()
            {
                Description = clientModel.Description,
                Cnpj        = clientModel.Cnpj,
                Situation   = clientModel.Situation
            };

            context.Entry(client).State = EntityState.Added;
            await context.SaveChangesAsync();

            await context.Entry(client).ReloadAsync();

            clientModel.Id = client.Id;

            return(clientModel);
        }
Esempio n. 27
0
        public async Task <ActionResult> Update([FromServices] RhNetContext rhNetContext, [FromBody] QuadroModel quadroModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            QuadroRepository repository = new QuadroRepository();
            object           result     = await repository.Update(rhNetContext, quadroModel);

            if (result.GetType() == typeof(QuadroModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Esempio n. 28
0
        public async Task <ActionResult> Add([FromServices] RhNetContext rhNetContext, [FromBody] MunicipioModel municipioModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            MunicipioRepository repository = new MunicipioRepository();
            object result = await repository.Add(rhNetContext, municipioModel);

            if (result.GetType() == typeof(MunicipioModel))
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.ToString()));
            }
        }
Esempio n. 29
0
        public async Task <Object> RemoveFavorite(RhNetContext context, string userName, FavoriteModel favoriteModel)
        {
            Favorite favorite = await(from x in context.Favorites
                                      from y in context.Users.Where(e => e.UserName == userName)
                                      from z in context.ApplicationMenus.Where(e => e.Path == favoriteModel.Path && e.Role_Name == favoriteModel.Profile)
                                      select x).FirstOrDefaultAsync();

            if (favorite == null)
            {
                return("Favorito não encontrado");
            }



            context.Entry(favorite).State = EntityState.Deleted;
            await context.SaveChangesAsync();

            return(favoriteModel);
        }
Esempio n. 30
0
        public async Task <QuadroModel> Get(RhNetContext rhNetContext, int id)
        {
            QuadroModel quadroModel = await(from x in rhNetContext.Quadros
                                            where x.Id == id
                                            orderby x.Descricao
                                            select new QuadroModel()
            {
                Descricao = x.Descricao,
                Id        = x.Id
            }).FirstOrDefaultAsync();

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

            quadroModel.Subquadros = await(from x in rhNetContext.Subquadros
                                           where x.Quadro_Id == quadroModel.Id
                                           select new SubquadroModel()
            {
                Id        = x.Id,
                Descricao = x.Descricao,
                Sigla     = x.Sigla
            }).ToListAsync();

            quadroModel.Atos_Normativos = await(from x in rhNetContext.Quadros_Atos_Normativos
                                                from y in rhNetContext.Atos_Normativos.Where(e => e.Id == x.Ato_Normativo_Id)
                                                from z in rhNetContext.Tipos_de_Ato_Normativo.Where(e => e.Id == y.Tipo_de_Ato_Normativo_Id)
                                                where x.Quadro_Id == quadroModel.Id
                                                select new Ato_NormativoModel()
            {
                Id                              = y.Id,
                Descricao                       = y.Descricao,
                Ano                             = y.Ano,
                Numero                          = y.Numero,
                Publicacao_Data                 = y.Publicacao_Data,
                Vigencia_Data                   = y.Vigencia_Data,
                Tipo_de_Ato_Normativo_Id        = z.Id,
                Tipo_de_Ato_Normativo_Descricao = z.Descricao
            }).ToListAsync();
            return(quadroModel);
        }