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 bool FileExists(DateTime date) { OrderRepository repo = new OrderRepository(); return repo.FileExists(date); }