public Response<Order> AddOrder(Order order, DateTime date) { var repo = new OrderRepository(); var response = new Response<Order>(); if (repo.FileExists(date)) { order.OrderNumber = repo.HighestOrderNumber(date) + 1; try { repo.CreateOrder(order, date); response.Success = true; response.Data = order; } catch (Exception ex) { response.Success = false; response.Message = "There was an error adding the order: " + ex.Message; repo.ErrorLogger(ex.Message); } return response; } else { order.OrderNumber = 1; try { repo.CreateFile(date); repo.CreateOrder(order, date, true); response.Success = true; response.Data = order; } catch (Exception ex) { response.Success = false; response.Message = "There was an error adding the order: " + ex.Message; repo.ErrorLogger(ex.Message); } return response; } }
public Response<List<Order>> DisplayOrders(DateTime date) { var repo = new OrderRepository(); var response = new Response<List<Order>>(); try { var orders = repo.LoadOrders(date); if (orders == null) { response.Success = false; response.Message = "A file with that date was not found."; } else { response.Success = true; response.Data = orders; } } catch (Exception ex) { response.Success = false; response.Message = "There was an error with Loading the File: " + ex.Message; repo.ErrorLogger(ex.Message); } return response; }
public Response<Order> RemoveOrder(int orderNumber, DateTime date) { OrderRepository repo = new OrderRepository(); var response = new Response<Order>(); try { repo.DeleteOrder(orderNumber, date); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = "There was an error with deleting the order: " + ex.Message; repo.ErrorLogger(ex.Message); } //check to see if it deleted the last order in the file, if so, delete the file also var orders = repo.LoadOrders(date); if (orders.Count == 0) { repo.DeleteFile(); } return response; }
public Response<EditReceipt> EditOrder(Order updatedOrder, DateTime date) { OrderRepository repo = new OrderRepository(); var response = new Response<EditReceipt>(); try { repo.UpdateOrder(updatedOrder, date); response.Success = true; } catch (Exception ex) { response.Success = false; response.Message = "There was an error with updating the order: " + ex.Message; repo.ErrorLogger(ex.Message); } return response; }