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)); }
public void CreateCaja(Caja caja) { using (EPracticoDBEntities entities = new EPracticoDBEntities()) { entities.Caja.Add(caja); entities.SaveChanges(); } }
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(); } }
public void CreateCliente(Cliente cliente) { if (cliente.ValidaCliente()) { using (EPracticoDBEntities entities = new EPracticoDBEntities()) { entities.Cliente.Add(cliente); entities.SaveChanges(); } } }
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); }
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(); } }
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(); } }