예제 #1
0
        public async Task <ActionResult> RegistrarMedicamento(HospitalMedicamentosCreateDTO hospitalMedicamentos)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44349");
                var ck = ControllerContext.HttpContext.Request.Cookies["Token"];
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ck);
                var response = await client.GetAsync($"api/CatalogoGrupoMedicamentos");

                if (response.IsSuccessStatusCode)
                {
                    List <SelectListItem> lst = new List <SelectListItem>();
                    foreach (var speciality in JsonConvert.DeserializeObject <List <CatalogoGrupoMedicamentos> >(await response.Content.ReadAsStringAsync()).ToList())
                    {
                        lst.Add(new SelectListItem()
                        {
                            Text = $"{speciality.Type}", Value = $"{speciality.Id}"
                        });
                    }
                    ViewBag.GrupoMedicamentos = lst;
                    return(View());
                }
                return(NotFound());
            }
        }
예제 #2
0
        public async Task <ActionResult> CrearMedicamento(HospitalMedicamentosCreateDTO crearMedicamento)
        {
            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 handler   = new JwtSecurityTokenHandler();
                var jsonToken = handler.ReadJwtToken(ck);
                var tokens    = jsonToken as JwtSecurityToken;

                crearMedicamento.hospitalId = tokens.Claims.First(claim => claim.Type == "HospitalId").Value;
                var postTask = await client.PostAsJsonAsync <HospitalMedicamentosCreateDTO>("api/HospitalMedicamentos", crearMedicamento);

                if (postTask.IsSuccessStatusCode)
                {
                    return(RedirectToAction("ListaMedicamentos", "Hospitals", new { hospitalId = crearMedicamento.hospitalId }));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
                    return(View("CrearMedicamento"));
                }
            }
        }
        public async Task <ActionResult <HospitalMedicamentosDTO> > AddHospitalMedicamentos([FromBody] HospitalMedicamentosCreateDTO hospitalMedicamentosCreateDTO)
        {
            var medExists = await context.HospitalMedicamentos.FirstOrDefaultAsync(x => x.HospitalId.Equals(hospitalMedicamentosCreateDTO.HospitalId) && x.NombreMedicamento.Equals(hospitalMedicamentosCreateDTO.NombreMedicamento.ToUpper()));

            if (medExists is not null)
            {
                return(BadRequest());
            }
            var hospitalMedicamento = new HospitalMedicamentos {
                HospitalId          = hospitalMedicamentosCreateDTO.HospitalId,
                Descripcion         = hospitalMedicamentosCreateDTO.Descripcion.ToUpper(),
                ViaAdministracion   = hospitalMedicamentosCreateDTO.ViaAdministracion,
                Indicaciones        = hospitalMedicamentosCreateDTO.Indicaciones,
                NombreMedicamento   = hospitalMedicamentosCreateDTO.NombreMedicamento.ToUpper(),
                GrupoMedicamentosId = hospitalMedicamentosCreateDTO.GrupoMedicamentosId,
                Precauciones        = hospitalMedicamentosCreateDTO.Precauciones,
                EfectosSecundarios  = hospitalMedicamentosCreateDTO.EfectosSecundarios
            };
            await context.HospitalMedicamentos.AddAsync(hospitalMedicamento);

            await context.SaveChangesAsync();

            return(Ok());
        }