internal bool guardarAltaEnBD()
        {
            using (ContextoEntity conec = new ContextoEntity())
            {
                if (conec.Propiedads.Any(p => p.nombre == this.nombre)) //no se guarda la propiedad xq existe otra con el mismo nombre

                {
                    MessageBox.Show("Error. Ya existe una propiedad con ese nombre");
                    return(false);
                }
                else if (this.existe()) //No se guarda la prop xq existe otra en la misma dirección y misma ciudad
                {
                    MessageBox.Show("Error. Ya existe una propiedad en esa dirección");
                    return(false);
                }
                else
                {
                    try
                    {
                        conec.Propiedads.Add(this);
                        conec.SaveChanges();
                        return(true);
                    }
                    catch
                    {
                        MessageBox.Show("Ocurrió un error en el guardado de datos");
                        return(false);
                    }
                }
            }
        }
 public bool existe()
 {
     using (ContextoEntity conexion = new ContextoEntity())
     {
         return(conexion.Propiedads.Any(p => p.ubicaciòn == this.ubicaciòn && p.ciudad == this.ciudad && p.provincia == this.provincia && p.pais == this.pais));
     }
 }
Exemple #3
0
 public static List <subasta> llenarConSubasta(int idProp)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.subastas.Where(p => p.id_propiedad_subastada == idProp).ToList());
     }
 }
Exemple #4
0
        public void cancelarGanador(xucReservasFuturas UcQueLoLlama)
        {
            try
            {
                using (ContextoEntity conec = new ContextoEntity())
                {
                    if (Semanizador.LunesDeSemana(this.añoReservado, this.semanaReservada) >= DateTime.Now.AddMonths(6))
                    {
                        this.usuario.agregarCredito();
                        conec.Entry(this.usuario).State = System.Data.Entity.EntityState.Modified;
                    }


                    //conec.ReservaDirectas.Remove(ReservaDirecta.getOneById(this.id));
                    conec.Entry(this).State = System.Data.Entity.EntityState.Deleted;
                    conec.SaveChanges();
                }
                UcQueLoLlama.inicializar();
                MessageBox.Show("Se canceló la reserva con éxito");
            }
            catch (Exception e)
            {
                MessageBox.Show("Hubo un error en la cancelación de la reserva");
                throw e;
            }
        }
 public static HotSale getOneById(int idP)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.HotSales.Where(p => p.id == idP).First());
     }
 }
 public static List <HotSale> traerDeDB()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.HotSales.Include(p => p.Propiedad).ToList());
     }
 }
 public static List <HotSale> traerDeDB(int proid)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.HotSales.Where(p => p.idPropiedad == proid).ToList());
     }
 }
Exemple #8
0
 public static List <subasta> llenarConSubasta()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.subastas.ToList());
     }
 }
 public static usuario traerDeDb(string mailParam, string mailPass)
 {
     using (ContextoEntity conexion = new ContextoEntity())
     {
         if (!conexion.usuarios.Any(p => p.mail == mailParam))
         {
             MessageBox.Show(string.Format("El mail {0} no se encuentra registrado", mailParam));
             return(null);
         }
         else
         {
             var usuarioEnDB = conexion.usuarios.Where(p => p.mail == mailParam && p.contraseña == mailPass).FirstOrDefault();
             if (usuarioEnDB != null)
             {
                 MessageBox.Show(string.Format("Logueado como usuario: {0}", mailParam));
                 return(usuarioEnDB);
             }
             else
             {
                 MessageBox.Show("ERROR. Contraseña inválida");
                 return(null);
             }
         }
     }
 }
 public static usuario getUsuarioFromId(string mailP)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.usuarios.Where(p => p.mail == mailP).FirstOrDefault());
     }
 }
Exemple #11
0
 public void crear()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         conec.subastas.Add(this);
         conec.SaveChanges();
     }
 }
 public static Boolean existeMailEnBaseDeDatos(string mail)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         var mailEnDB = conec.usuarios.Where(each => each.mail == mail).FirstOrDefault();
         return(mailEnDB != null);
     }
 }
 public void crear()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         conec.usuarioParticipaEnSubastas.Add(this);
         conec.SaveChanges();
     }
 }
Exemple #14
0
 public static ReservaDirecta getOneById(int idP)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.ReservaDirectas
                .Include(a => a.usuario)
                .Where(p => p.id == idP).First());
     }
 }
 public void restarCredito()
 {
     this.token--;
     using (ContextoEntity con = new ContextoEntity())
     {
         con.Entry(this).State = EntityState.Modified;
         con.SaveChanges();
     }
 }
 public static ganadorDeSubasta getOneById(int idP)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         return(conec.ganadorDeSubastas
                .Include(a => a.usuario)
                .Include(a => a.subasta)
                .Where(p => p.id == idP).First());
     }
 }
Exemple #17
0
 public xUCCerrarSubasta()
 {
     InitializeComponent();
     // This line of code is generated by Data Source Configuration Wizard
     // Instantiate a new DBContext
     HSH_Desa_y_Test.ContextoDB.ContextoEntity dbContext = new HSH_Desa_y_Test.ContextoDB.ContextoEntity();
     // Call the LoadAsync method to asynchronously get the data for the given DbSet from the database.
     dbContext.subastas.LoadAsync().ContinueWith(loadTask =>
     {
         // Bind data to control when loading complete
         gridControl1.DataSource = dbContext.subastas.Local.ToBindingList();
     }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
 }
Exemple #18
0
 public usuarioParticipaEnSubasta encontrarGanador()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         var candidatos = this.usuarioParticipaEnSubastas.OrderByDescending(q => q.monto).ToArray();
         for (int i = 0; i < candidatos.Length; i++)
         {
             if (usuario.getUsuarioFromId(candidatos[i].idPersona).token > 0)
             {
                 return(candidatos[i]);
             }
         }
         return(null);
     }
 }
 public bool actualizarPropiedadEnBd()
 {
     try
     {
         using (ContextoEntity conexion = new ContextoEntity())
         {
             conexion.Entry <Propiedad>(this).State = EntityState.Modified;
             conexion.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemple #20
0
 public static admin traerDeDb(string tokenParam)
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         var adminLogueado = conec.admins.Where(p => p.token == tokenParam).FirstOrDefault();
         if (adminLogueado != null)
         {
             MessageBox.Show("Logueado como administrador con éxito");
             return(adminLogueado);
         }
         else
         {
             MessageBox.Show("Token de adminstrador Inválido");
             return(null);
         }
     }
 }
 public bool guardarEnBD()
 {
     using (ContextoEntity conec = new ContextoEntity())
     {
         try
         {
             conec.HotSales.Add(this);
             conec.SaveChanges();
             return(true);
         }
         catch
         {
             MessageBox.Show("Hubo un error en el guardado de la base de datos");
             return(false);
         }
     }
 }
 public void cancelarGanador(xucReservasFuturas UcQueLoLlama)
 {
     try
     {
         using (ContextoEntity conec = new ContextoEntity())
         {
             this.idUsuario          = null;
             conec.Entry(this).State = System.Data.Entity.EntityState.Modified;
             conec.SaveChanges();
             UcQueLoLlama.inicializar();
             MessageBox.Show("Se canceló el hotsale con éxito");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        internal bool EstaLibre(int semana, int año, bool saltarMensajes)
        {
            Propiedad propDeDb;

            using (ContextoEntity conec = new ContextoEntity())
            {
                propDeDb = conec.Propiedads
                           .Include(a => a.ReservaDirectas)
                           .Include(a => a.HotSales)
                           .Include(a => a.subastas)
                           .Where(p => p.id == this.id).FirstOrDefault();
            }
            DateTime diaParaCheckear = Semanizador.LunesDeSemana(año, semana);

            if (propDeDb.ReservaDirectas.Any(p => p.semanaReservada == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya está reservada para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una reserva");
                }
                return(false);
            }
            else if (propDeDb.subastas.Any(p => p.semana_de_subasta == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya tiene una subasta para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una subasta");
                }
                return(false);
            }
            else if (propDeDb.HotSales.Any(p => p.semanaReservada == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya tiene un HotSale reservado para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una reserva");
                }
                return(false);
            }

            return(true);
        }
Exemple #24
0
        public void cerrar()
        {
            var pujaGanadora = encontrarGanador();

            if (pujaGanadora != null)
            {
                using (ContextoEntity conec = new ContextoEntity())
                {
                    conec.ganadorDeSubastas.Add(new ganadorDeSubasta(pujaGanadora.idPersona, this.id, pujaGanadora.id));
                    var usuarioGanador = conec.usuarios.Where(p => p.mail == pujaGanadora.idPersona).First();
                    usuarioGanador.token--;
                    conec.Entry(usuarioGanador).State = System.Data.Entity.EntityState.Modified;
                    MessageBox.Show(String.Format("Se cerró la subasta\nGanador de la subasta: {0}\nMonto ganador: {1}", usuarioGanador.mail, pujaGanadora.monto));
                    conec.SaveChanges();
                }
            }
            else
            {
                MessageBox.Show(String.Format("Se cerró la subasta\nNo hubo ganadores"));
            }
        }
 public void cancelarGanador(xucReservasFuturas UcQueLoLlama)
 {
     try
     {
         using (ContextoEntity conec = new ContextoEntity())
         {
             if (Semanizador.LunesDeSemana(this.subasta.añoReservado, this.subasta.semana_de_subasta) >= DateTime.Now.AddMonths(6))
             {
                 this.usuario.agregarCredito();
                 conec.Entry(this.usuario).State = System.Data.Entity.EntityState.Modified;
             }
             conec.ganadorDeSubastas.Remove(this);
             conec.SaveChanges();
             UcQueLoLlama.inicializar();
             MessageBox.Show("Se canceló la reserva con éxito");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }