예제 #1
0
        public void AddCajaCliente(Cliente cliente, EPracticoDBEntities entities)
        {
            var cajas = entities.CajaCliente.Where(z => z.Caja.EstadoCajaID == 1).GroupBy(x => x.CajaID).Select(y => new { CajaID = y.Key, CantAtendido = y.Sum(x => x.EstadoCajaClienteID) });

            var cajaMenosUsada = cajas.OrderBy(x => x.CantAtendido).FirstOrDefault();

            entities.CajaCliente.Add(new CajaCliente(cajaMenosUsada.CajaID, cliente.ClienteID));
        }
예제 #2
0
 public void CreateCaja(Caja caja)
 {
     using (EPracticoDBEntities entities = new EPracticoDBEntities())
     {
         entities.Caja.Add(caja);
         entities.SaveChanges();
     }
 }
예제 #3
0
        public void AttendCliente(int cajaID)
        {
            using (EPracticoDBEntities entities = new EPracticoDBEntities())
            {
                var cajaCliente = entities.CajaCliente.FirstOrDefault(x => x.CajaID == cajaID && x.EstadoCajaClienteID == 2);

                UpdateCajaCliente(cajaCliente);

                entities.SaveChanges();
            }
        }
예제 #4
0
        public void CreateCliente(Cliente cliente)
        {
            if (cliente.ValidaCliente())
            {
                using (EPracticoDBEntities entities = new EPracticoDBEntities())
                {
                    entities.Cliente.Add(cliente);

                    entities.SaveChanges();
                }
            }
        }
예제 #5
0
        private bool ExistCajaInCajaCliente(EPracticoDBEntities entities)
        {
            foreach (var item in entities.Caja.OrderBy(x => x.CajaID))
            {
                var existeCaja = entities.CajaCliente.Any(x => x.CajaID == item.CajaID);
                if (!existeCaja)
                {
                    this.CajaID = item.CajaID;
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
 public void CloseCaja(int cajaID)
 {
     using (EPracticoDBEntities entities = new EPracticoDBEntities())
     {
         CajaClienteService cajaClienteService = new CajaClienteService();
         var caja = entities.Caja.FirstOrDefault(x => x.CajaID == cajaID);
         UpdateCaja(caja);
         entities.SaveChanges();
         var cajaClientes = entities.CajaCliente.Where(x => x.CajaID == caja.CajaID && x.EstadoCajaClienteID == 2);
         foreach (var item in cajaClientes)
         {
             cajaClienteService.AddCajaCliente(item.Cliente, entities);
         }
         entities.SaveChanges();
     }
 }
예제 #7
0
 public void CreateCajaCliente(Cliente cliente)
 {
     using (EPracticoDBEntities entities = new EPracticoDBEntities())
     {
         if (ExistCajaInCajaCliente(entities) || entities.CajaCliente.Any())
         {
             if (this.CajaID > 0)
             {
                 entities.CajaCliente.Add(new CajaCliente(this.CajaID, cliente.ClienteID));
             }
             else
             {
                 AddCajaCliente(cliente, entities);
             }
         }
         else
         {
             entities.CajaCliente.Add(new CajaCliente(entities.Caja.FirstOrDefault().CajaID, cliente.ClienteID));
         }
         entities.SaveChanges();
     }
 }