public Reservation(ReservationRecord record) { id = record.id; showId = record.showId; userId = record.userId; chairId = record.chairId; }
// Deletes the specified chair public bool DeleteReservation(Reservation reservation) { Database database = Program.GetInstance().GetDatabase(); ReservationRecord record = database.reservations.SingleOrDefault(i => i.id == reservation.id); // Return false if room doesn't exist if (record == null) { return(false); } // Remove record database.reservations.Remove(record); // TODO: Remove related reservations // Try to save database.TryToSave(); return(true); }
// Saves the specified reservation public bool SaveReservation(Reservation reservation) { Database database = Program.GetInstance().GetDatabase(); bool isNew = reservation.id == -1; // Validate and add if valid if (!reservation.Validate()) { return(false); } // Set id if its a new user if (isNew) { reservation.id = database.GetNewId("reservations"); } // Find existing record ReservationRecord record = database.reservations.SingleOrDefault(i => i.id == reservation.id); // Add if no record exists if (record == null) { record = new ReservationRecord(); database.reservations.Add(record); } // Update record record.id = reservation.id; record.showId = reservation.showId; record.userId = reservation.userId; record.chairId = reservation.chairId; // Try to save database.TryToSave(); return(true); }
public void GenerateReport(MozuContext mozuContext, string outputFilePath) { List<ReservationRecord> records = new List<ReservationRecord>(); // get all reservations var reservations = GetProductReservations(mozuContext); Console.WriteLine("Loaded {0} reservations.", reservations == null ? 0 : reservations.Length); int ix = 0; // loop through reservations foreach (var reservation in reservations) { if (ix++ % 5 == 0) { Console.Write("."); } ReservationRecord r = new ReservationRecord() { ProductReservationId = reservation.Id, LocationCode = reservation.LocationCode, OrderId = reservation.OrderId, OrderNumber = null, // filled in below ProductCode = reservation.ProductCode, Quantity = reservation.Quantity, ProductName = null, // filled in below ReservationCreateDate = reservation.AuditInfo == null ? null : reservation.AuditInfo.CreateDate, OrderSubmittedDate = null, // filled in below OrderStatus = null, // filled in below OrderFulfillmentStatus = null // filled in below }; if (reservation.AuditInfo != null) { r.ReservationCreateDate = reservation.AuditInfo.CreateDate; } // look up order var order = GetOrderById(mozuContext, reservation.OrderId); if (order == null) { Console.WriteLine("Order {0} not found", reservation.OrderId); } else { r.OrderNumber = order.OrderNumber.Value.ToString(); r.OrderSubmittedDate = order.SubmittedDate; r.OrderStatus = order.Status; r.OrderFulfillmentStatus = order.FulfillmentStatus; // find the order line var orderLine = order.Items.Where(o => o.Id == reservation.OrderItemId).FirstOrDefault(); if (orderLine == null) { Console.WriteLine("OrderItemId {0} not found", reservation.OrderItemId); r.ProductName = String.Format("[OrderItemId = {0} not found]", reservation.OrderItemId); } else { r.Quantity = orderLine.Quantity; if (orderLine.Product != null) { r.ProductName = orderLine.Product.Name; if (orderLine.Product.BundledProducts != null && orderLine.Product.BundledProducts.Count > 0) { // bundle component var product = GetProductById(mozuContext, reservation.ProductCode); if (product != null && product.Content != null) { r.ProductName = String.Format("{0} ({1})", product.Content.ProductName, orderLine.Product.Name); } } } } } records.Add(r); } Console.WriteLine("."); string s = CSVUtil.ToCSV(records.ToArray()); File.WriteAllText(outputFilePath, s, Encoding.UTF8); }
public void GenerateReport(MozuContext mozuContext, string outputFilePath) { List <ReservationRecord> records = new List <ReservationRecord>(); // get all reservations var reservations = GetProductReservations(mozuContext); Console.WriteLine("Loaded {0} reservations.", reservations == null ? 0 : reservations.Length); int ix = 0; // loop through reservations foreach (var reservation in reservations) { if (ix++ % 5 == 0) { Console.Write("."); } ReservationRecord r = new ReservationRecord() { ProductReservationId = reservation.Id, LocationCode = reservation.LocationCode, OrderId = reservation.OrderId, OrderNumber = null, // filled in below ProductCode = reservation.ProductCode, Quantity = reservation.Quantity, ProductName = null, // filled in below ReservationCreateDate = reservation.AuditInfo == null ? null : reservation.AuditInfo.CreateDate, OrderSubmittedDate = null, // filled in below OrderStatus = null, // filled in below OrderFulfillmentStatus = null // filled in below }; if (reservation.AuditInfo != null) { r.ReservationCreateDate = reservation.AuditInfo.CreateDate; } // look up order var order = GetOrderById(mozuContext, reservation.OrderId); if (order == null) { Console.WriteLine("Order {0} not found", reservation.OrderId); } else { r.OrderNumber = order.OrderNumber.Value.ToString(); r.OrderSubmittedDate = order.SubmittedDate; r.OrderStatus = order.Status; r.OrderFulfillmentStatus = order.FulfillmentStatus; // find the order line var orderLine = order.Items.Where(o => o.Id == reservation.OrderItemId).FirstOrDefault(); if (orderLine == null) { Console.WriteLine("OrderItemId {0} not found", reservation.OrderItemId); r.ProductName = String.Format("[OrderItemId = {0} not found]", reservation.OrderItemId); } else { r.Quantity = orderLine.Quantity; if (orderLine.Product != null) { r.ProductName = orderLine.Product.Name; if (orderLine.Product.BundledProducts != null && orderLine.Product.BundledProducts.Count > 0) { // bundle component var product = GetProductById(mozuContext, reservation.ProductCode); if (product != null && product.Content != null) { r.ProductName = String.Format("{0} ({1})", product.Content.ProductName, orderLine.Product.Name); } } } } } records.Add(r); } Console.WriteLine("."); string s = CSVUtil.ToCSV(records.ToArray()); File.WriteAllText(outputFilePath, s, Encoding.UTF8); }