public void saveSale() { saleID = Controler.Instance.getLastSaleId() + 1; int sellerID = Controler.Instance.getCurrentUser().getId(); int clientID = client.getId(); DateTime sale_date = DateTime.Now; DateTime prevision_date = getNextPrevisionDate(); //date de début de constrution List <User> userList = Controler.Instance.getUserList(); List <Client> clientList = Controler.Instance.getClientList(); Sale sale = new Sale(saleID, sellerID, clientID, "Open", sale_date, prevision_date, userList, clientList); Controler.Instance.createSale(sale); foreach (BikeBasket b in Basket.Values) { BikeTemplate bt = b.CreateBikeTemplate(); if (bt.getId() == -1) { int id_bt = Controler.Instance.getLastBikeTemplateId() + 1; bt.setId(id_bt); Controler.Instance.createBikeTemplate(bt); } for (int i = 0; i < b.qnt; i++) { int bikeID = Controler.Instance.getLastBikeId() + 1; //check if we have a bike in stock List <Bike> BikeStock = Controler.Instance.getBikesList().Where(x => ((x.getSaleId() == -1) && (x.getState() == 2) && (x.getBikeTempl().Key == bt.Key))).ToList(); // list of bike witch correspond to the requested bike if (BikeStock.Count > 0) { Bike temp_bikeStock = BikeStock.First(); temp_bikeStock.setSaleId(saleID); sale.addbike(temp_bikeStock); DatabaseClassInterface.updateBike(temp_bikeStock); } else { // if not create a new one DateTime constr_date = getConstrDate(); DateTime planned_date = getNextPrevisionDate(); int poste = Controler.Instance.getAvailablePoste(); Bike tempB = new Bike(bikeID, 0, saleID, poste, bt, planned_date, constr_date); sale.addbike(tempB); Controler.Instance.createBike(tempB); } } } Bike bk = sale.getBikeList().Last(); sale.setPrevSaleDate(bk.getPlannedtDate()); drainTempSale(); }
public void createBike(Bike b) { bikeList.Add(b); DatabaseClassInterface.addBike(b); }
public void addbike(Bike b) { //bikeList.Add(b); }