Esempio n. 1
0
        public async Task <ActionResult> CreateGrupoMedicamentos([FromBody] ListadoGrupoMedicamentosDTO grupo)
        {
            await context.CatalogoGrupoMedicamentos.AddAsync(new CatalogoGrupoMedicamentos { Type = grupo.Type });

            await context.SaveChangesAsync();

            var grupoMedicamentos = await context.CatalogoGrupoMedicamentos.FirstOrDefaultAsync(x => x.Type.Equals(grupo.Type));

            return(new CreatedAtRouteResult("GrupoMedicamentosInfo", new { id = grupoMedicamentos.Id }, grupo));
        }
        public async Task <ActionResult> Medicamentos(ListadoGrupoMedicamentosDTO listadogrupoMedicamentos)
        {
            using (var client = new HttpClient())
            {
                var ck = ControllerContext.HttpContext.Request.Cookies["Token"];
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ck);
                client.BaseAddress = new Uri("https://localhost:44349");
                var response = await client.GetAsync("api/CatalogoGrupoMedicamentos");

                if (response.IsSuccessStatusCode)
                {
                    return(View(JsonConvert.DeserializeObject <List <ListadoGrupoMedicamentosDTO> >(await client.GetStringAsync("https://localhost:44349/api/CatalogoGrupoMedicamentos")).ToList()));
                }
                return(NotFound());
            }
        }
        public async Task <ActionResult> DeleteMedicamentos(ListadoGrupoMedicamentosDTO listadogrupoMedicamentos)
        {
            using (var client = new HttpClient())
            {
                var ck = ControllerContext.HttpContext.Request.Cookies["Token"];
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ck);
                client.BaseAddress = new Uri("https://*****:*****@"Medicamentos"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                    return(View("Medicamentos"));
                }
            }
        }