List <MedicamentoCLS> IService1.listarMedicamentos() { List <MedicamentoCLS> listaMedicamento = new List <MedicamentoCLS>(); try { using (var bd = new MedicoEntities()) { listaMedicamento = (from medicamento in bd.Medicamento join formafarmaceutica in bd.FormaFarmaceutica on medicamento.IIDFORMAFARMACEUTICA equals formafarmaceutica.IIDFORMAFARMACEUTICA select new MedicamentoCLS { idMedicamento = medicamento.IIDMEDICAMENTO, nombre = medicamento.NOMBRE, presentacion = medicamento.PRESENTACION, precio = (decimal)medicamento.PRECIO, concentracion = medicamento.CONCENTRACION, stock = (int)medicamento.STOCK }).ToList(); } } catch (Exception) { listaMedicamento = null; } return(listaMedicamento); }
MedicamentoCLS IMedicamentos.RecuperarMedicamento(int iidMedicamento) { //throw new NotImplementedException(); MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS(); try { using (var bd = new MedicoEntities()) { Medicamento oMedicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == iidMedicamento).First(); oMedicamentoCLS.IidMedicamento = oMedicamento.IIDMEDICAMENTO; oMedicamentoCLS.IidFormaFarmaceutica = (int)oMedicamento.IIDFORMAFARMACEUTICA; oMedicamentoCLS.Nombre = oMedicamento.NOMBRE; oMedicamentoCLS.Precio = (decimal)oMedicamento.PRECIO; oMedicamentoCLS.Stock = (int)oMedicamento.STOCK; oMedicamentoCLS.Concentracion = oMedicamento.CONCENTRACION; oMedicamentoCLS.Presentacion = oMedicamento.PRESENTACION; } } catch (Exception) { oMedicamentoCLS = null; } return(oMedicamentoCLS); }
List <MedicamentoCLS> IMedicamentos.ListarMedicamentos() { //throw new NotImplementedException(); List <MedicamentoCLS> ListaMedicamento = new List <MedicamentoCLS>(); try { using (var bd = new MedicoEntities()) { ListaMedicamento = (from medicamento in bd.Medicamento join formafarmaceutica in bd.FormaFarmaceutica on medicamento.IIDFORMAFARMACEUTICA equals formafarmaceutica.IIDFORMAFARMACEUTICA select new MedicamentoCLS { IidMedicamento = medicamento.IIDMEDICAMENTO, Nombre = medicamento.NOMBRE, Precio = (decimal)medicamento.PRECIO, NombreFormaFarmaceutica = formafarmaceutica.NOMBRE, Concentracion = medicamento.CONCENTRACION, Presentacion = medicamento.PRESENTACION, Stock = (int)medicamento.STOCK, BHabilitado = (int)medicamento.BHABILITADO }).ToList(); } } catch (Exception) { ListaMedicamento = null; } return(ListaMedicamento); }
int IMedicamentos.RegistraryActualizarMedicamento(MedicamentoCLS oMedicamentoCLS) { //throw new NotImplementedException(); int rpta = 0; try { using (var bd = new MedicoEntities()) { if (oMedicamentoCLS.IidMedicamento == 0) { Medicamento oMedicamento = new Medicamento(); oMedicamento.IIDMEDICAMENTO = oMedicamentoCLS.IidMedicamento; oMedicamento.NOMBRE = oMedicamentoCLS.Nombre; oMedicamento.PRECIO = oMedicamentoCLS.Precio; oMedicamento.STOCK = oMedicamentoCLS.Stock; oMedicamento.IIDFORMAFARMACEUTICA = oMedicamentoCLS.IidFormaFarmaceutica; oMedicamento.CONCENTRACION = oMedicamentoCLS.Concentracion; oMedicamento.PRESENTACION = oMedicamentoCLS.Presentacion; oMedicamento.BHABILITADO = 1; bd.Medicamento.Add(oMedicamento); bd.SaveChanges(); rpta = 1; } else { Medicamento oMedicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == oMedicamentoCLS.IidMedicamento).First(); oMedicamento.NOMBRE = oMedicamentoCLS.Nombre; oMedicamento.PRECIO = oMedicamentoCLS.Precio; oMedicamento.STOCK = oMedicamentoCLS.Stock; oMedicamento.IIDFORMAFARMACEUTICA = oMedicamentoCLS.IidFormaFarmaceutica; oMedicamento.CONCENTRACION = oMedicamentoCLS.Concentracion; oMedicamento.PRESENTACION = oMedicamentoCLS.Presentacion; bd.SaveChanges(); rpta = 1; } } } catch (Exception ex) { rpta = 0; } return(rpta); }
int IService1.eliminarMedicamento(int idMedicamento) { int respuesta = 0; try { using (var bd = new MedicoEntities()) { Medicamento oMedicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == idMedicamento).First(); oMedicamento.BHABILITADO = 0; bd.SaveChanges(); respuesta = 1; } } catch (Exception exc) { respuesta = 0; } return(respuesta); }
List <FormaFarmaceuticaCLS> IService1.listarFormaFarmaceutica() { List <FormaFarmaceuticaCLS> listaFormaFarmaceutica = new List <FormaFarmaceuticaCLS>(); try { using (var bd = new MedicoEntities()) { listaFormaFarmaceutica = bd.FormaFarmaceutica.Select(p => new FormaFarmaceuticaCLS { idFormaFarmaceutica = p.IIDFORMAFARMACEUTICA, nombreFormaFarmaceutica = p.NOMBRE }).ToList(); } } catch (Exception exc) { listaFormaFarmaceutica = null; } return(listaFormaFarmaceutica); }
MedicamentoCLS IService1.recuperarMedicamento(int idMedicamento) { MedicamentoCLS oMedicamentoCLS = new MedicamentoCLS(); try { using (var bd = new MedicoEntities()) { Medicamento medicamento = bd.Medicamento.Where(p => p.IIDMEDICAMENTO == idMedicamento).First(); oMedicamentoCLS.idMedicamento = medicamento.IIDMEDICAMENTO; oMedicamentoCLS.nombre = medicamento.NOMBRE; oMedicamentoCLS.precio = (decimal)medicamento.PRECIO; oMedicamentoCLS.stock = (int)medicamento.STOCK; oMedicamentoCLS.concentracion = medicamento.CONCENTRACION; oMedicamentoCLS.presentacion = medicamento.PRESENTACION; } return(oMedicamentoCLS); } catch (Exception) { return(oMedicamentoCLS); } }
List <FormaFarmaceuticaCLS> IMedicamentos.ListaFormaFarmaceutica() { //throw new NotImplementedException(); List <FormaFarmaceuticaCLS> ListaFormaFarmaceutica = new List <FormaFarmaceuticaCLS>(); try { using (var bd = new MedicoEntities()) { ListaFormaFarmaceutica = bd.FormaFarmaceutica.Where(p => p.BHABILITADO == 1) .Select(p => new FormaFarmaceuticaCLS { IidFormaFarmaceutica = p.IIDFORMAFARMACEUTICA, NombreFormaFarmaceutica = p.NOMBRE }).ToList(); } } catch (Exception) { ListaFormaFarmaceutica = null; } return(ListaFormaFarmaceutica); }
int IMedicamentos.EliminarMedicamento(int iidMedicamento) { //throw new NotImplementedException(); int rpta = 0; using (var bd = new MedicoEntities()) { try { Medicamento oMedicamento = bd.Medicamento.Where(P => P.IIDMEDICAMENTO == iidMedicamento).First(); oMedicamento.BHABILITADO = 0; bd.SaveChanges(); rpta = 1; } catch (Exception) { rpta = 0; //throw; } return(rpta); } }