public IList <LugBulkReservation> GetReservations() { if (_reservations != null) { return(_reservations); } _reservations = new List <LugBulkReservation>(); GetBuyers(); GetElements(); var reservation_pos_list = SourceReaderHelper.GetCrossRangePositions (_buyers_span, _element_id_span); foreach (var reservation_pos in reservation_pos_list) { var reservation_amount = 0; // Skip if not a number if (!int.TryParse(_work_sheet.Cell(reservation_pos.Row, reservation_pos.Column) .Value.ToString(), out reservation_amount)) { continue; } // Skip 0 and less if (reservation_amount <= 0) { continue; } var element_id_pos = SourceReaderHelper.GetTitlePositionForValuePosition (reservation_pos, _element_id_span); var buyer_name_pos = SourceReaderHelper.GetTitlePositionForValuePosition (reservation_pos, _buyers_span); var element_id = _work_sheet.Cell(element_id_pos.Row, element_id_pos.Column) .Value.ToString().Trim(); var buyer_name = _work_sheet.Cell(buyer_name_pos.Row, buyer_name_pos.Column) .Value.ToString().Trim(); var reservation = new LugBulkReservation() { Element = _elements.Where(x => x.ElementID == element_id).First(), Buyer = _buyers.Where(x => x.Name == buyer_name).First(), Amount = reservation_amount, }; _reservations.Add(reservation); } return(_reservations); }
private void ParseOrders(List <string> orders) { _orders = new List <LugBulkReservation>(); foreach (var line in orders) { var parts = line.Split(','); if (parts[0] == "Nickname") { continue; } if (parts.Length != 4) { throw new Exception("Line doesn't have 4 parts: " + line); } var amount = 0; if (!int.TryParse(parts[3], out amount)) { throw new Exception("Line missing valid amount: " + line); } var buyer = _buyers.FirstOrDefault(x => x.Name == parts[0]); if (buyer == null) { throw new Exception("Line missing valid buyer: " + line); } var element = _elements.FirstOrDefault(x => x.ElementID == parts[2]); if (element == null) { throw new Exception("Line missing valid element: " + line); } var new_order = new LugBulkReservation() { Element = element, Buyer = buyer, Amount = amount, }; _orders.Add(new_order); } }