コード例 #1
0
        /// <summary>
        /// Obtener las ofertas por la id de subasta
        /// </summary>
        /// <param name="idSubasta"></param>
        /// <returns></returns>
        public static List <OfertaSubasta> ReadByIdSubasta(int idSubasta)
        {
            //Creacion de una factory de Transportista
            TipoUsuarioFactory   factory = new TransportistaFactory();
            List <OfertaSubasta> list    = new List <OfertaSubasta>();

            try
            {
                using (var db = new DBEntities())
                {
                    var listadoOfertas = db.OFERTASUBASTA.Where(of => of.IDSUBASTA == idSubasta).ToList();
                    if (listadoOfertas.Count() > 0)
                    {
                        foreach (var ofe in listadoOfertas)
                        {
                            OfertaSubasta oferta = new OfertaSubasta();
                            oferta.IdOferta      = (int)ofe.IDOFERTA;
                            oferta.FechaOferta   = ofe.FECHAOFERTA;
                            oferta.Seleccionado  = ofe.SELECCIONADO;
                            oferta.PrecioOferta  = (float)ofe.PRECIOOFERTA;
                            oferta.Transportista = (TiposUsuario.Transportista)factory.createTipoUsuario();
                            oferta.Transportista.ObtenerDatosPorId((int)ofe.IDTRANSPORTISTA);
                            oferta.IdSubasta = (int)ofe.IDSUBASTA;

                            TipoTransporte tipo = new TipoTransporte();
                            tipo.IdTipo = (int)ofe.IDTIPOTRANSPORTE;
                            tipo.GetById();
                            oferta.TipoTransporte = tipo;

                            list.Add(oferta);
                        }
                    }
                    return(list);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(new List <OfertaSubasta>());
            }
        }
コード例 #2
0
        public static TipoUsuario GetTipoUsuario(string rol, int idUsr)
        {
            TipoUsuario        tipoUsuario;
            TipoUsuarioFactory factory;

            try
            {
                switch (rol)
                {
                case "Cliente":
                    factory     = new ClienteFactory();
                    tipoUsuario = factory.createTipoUsuario();
                    tipoUsuario.ReadById(idUsr);
                    break;

                case "Productor":
                    factory     = new ProductorFactory();
                    tipoUsuario = factory.createTipoUsuario();
                    tipoUsuario.ReadById(idUsr);
                    break;

                case "Transportista":
                    factory     = new TransportistaFactory();
                    tipoUsuario = factory.createTipoUsuario();
                    tipoUsuario.ReadById(idUsr);
                    break;

                default:
                    tipoUsuario = null;
                    break;
                }
                return(tipoUsuario);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Buscar las ofertas de las subastas segun la id de esta
        /// </summary>
        /// <param name="idSubasta"></param>
        /// <returns></returns>
        public static List <OfertaSubasta> ListarOfertaPorIdSubasta(int idSubasta)
        {
            //Creacion de una factory de Transportista
            TipoUsuarioFactory factory = new TransportistaFactory();

            using (var db = new DBEntities())
            {
                try
                {
                    List <OfertaSubasta> listado = new List <OfertaSubasta>();

                    var queryOfertas = db.OFERTASUBASTA.Where(ofer => ofer.IDSUBASTA == idSubasta).ToList();
                    foreach (var oferta in queryOfertas)
                    {
                        OfertaSubasta ofertaSubasta = new OfertaSubasta();
                        ofertaSubasta.IdOferta      = (int)oferta.IDOFERTA;
                        ofertaSubasta.FechaOferta   = oferta.FECHAOFERTA;
                        ofertaSubasta.Seleccionado  = oferta.SELECCIONADO;
                        ofertaSubasta.PrecioOferta  = (float)oferta.PRECIOOFERTA;
                        ofertaSubasta.Transportista = (TiposUsuario.Transportista)factory.createTipoUsuario();
                        ofertaSubasta.Transportista.ObtenerDatosPorId((int)oferta.IDTRANSPORTISTA);
                        ofertaSubasta.IdSubasta = (int)oferta.IDSUBASTA;

                        TipoTransporte tipo = new TipoTransporte();
                        tipo.IdTipo = (int)oferta.IDTIPOTRANSPORTE;
                        tipo.GetById();
                        ofertaSubasta.TipoTransporte = tipo;
                        listado.Add(ofertaSubasta);
                    }
                    return(listado);
                }catch (Exception ex)
                {
                    ex.InnerException.ToString();
                    return(null);
                }
            }
        }