public ClientService(RavenDbConnection ravenDbConnection) { _ravenDbConnection = ravenDbConnection; _countriesDocumentStore.Initialize(); _countriesRegions.Add("UK", "EU"); _countriesRegions.Add("USA", "USA"); _countriesRegions.Add("Sweden", "EU"); _countriesRegions.Add("Spain", "EU"); _countriesRegions.Add("Slovenia", "EU"); _countriesRegions.Add("Slovakia", "EU"); _countriesRegions.Add("Romania", "EU"); _countriesRegions.Add("Portugal", "EU"); _countriesRegions.Add("Poland", "EU"); _countriesRegions.Add("Netherlands", "EU"); _countriesRegions.Add("Malta", "EU"); _countriesRegions.Add("Luxembourg", "EU"); _countriesRegions.Add("Lithuania", "EU"); _countriesRegions.Add("Latvia", "EU"); _countriesRegions.Add("Italy", "EU"); _countriesRegions.Add("Ireland", "EU"); _countriesRegions.Add("Hungary", "EU"); _countriesRegions.Add("Greece", "EU"); _countriesRegions.Add("Germany", "EU"); _countriesRegions.Add("France", "EU"); _countriesRegions.Add("Finland", "EU"); _countriesRegions.Add("Estonia", "EU"); _countriesRegions.Add("Denmark", "EU"); _countriesRegions.Add("Czech Republic", "EU"); _countriesRegions.Add("Cyprus", "EU"); _countriesRegions.Add("Croatia", "EU"); _countriesRegions.Add("Bulgaria", "EU"); _countriesRegions.Add("Belgium", "EU"); _countriesRegions.Add("Austria", "EU"); }
public virtual ActionResult Index(int currentPage = 1, int itemsPerPage = 15) { if (currentPage < 1) currentPage = 1; if (itemsPerPage < 1) itemsPerPage = 1; using (var rdbc = new RavenDbConnection(new RavenDbConnectionManager())) { var service = new ClientService(rdbc); var clients = service.GetClients(currentPage, itemsPerPage); var clientViewModels = new List<ClientEditViewModel>(clients.Results.Count); clientViewModels.AddRange(clients.Results.Select(client => new ClientEditViewModel(client))); var clientHomeViewModel = new ClientHomeViewModel { Clients = clientViewModels, CurrentPage = currentPage, ItemsPerPage = itemsPerPage }; foreach (var downServer in clients.ErrorConnectionStrings) { clientHomeViewModel.AddDownServers(downServer); } return View(clientHomeViewModel); } }
public virtual ActionResult Index(ClientEditViewModel clientEditViewModel) { using (var ravenDbConnection = new RavenDbConnection(new RavenDbConnectionManager())) { var service = new ClientService(ravenDbConnection); service.UpdateClient(clientEditViewModel.Id, clientEditViewModel.FirstName, clientEditViewModel.LastName, clientEditViewModel.Country); return RedirectToAction("Index", "Home"); } }
public virtual ActionResult Index(string id) { using (var ravenDbConnection = new RavenDbConnection(new RavenDbConnectionManager())) { var service = new ClientService(ravenDbConnection); service.DeleteClient(id); } return RedirectToAction("Index", "Home"); }
// // GET: /Edit/ public ActionResult Index(string id) { using (var ravenDbConnection = new RavenDbConnection(new RavenDbConnectionManager())) { var service = new ClientService(ravenDbConnection); var client = service.GetClient(id); var viewModel = new ClientEditViewModel(client); return View(viewModel); } }
public virtual ActionResult Index(ClientEditViewModel clientEdit) { try { using (var ravenDbConnection = new RavenDbConnection(new RavenDbConnectionManager())) { var service = new ClientService(ravenDbConnection); service.AddClient(clientEdit.FirstName, clientEdit.LastName, clientEdit.Country); } return RedirectToAction("Index"); } catch { return RedirectToAction("Index", "Home"); } }
public ActionResult AddOrder(OrdersAddViewModel order) { using (var rdbc = new RavenDbConnection(_rdcm)) { var orderService = new OrderService(rdbc); var clientService = new ClientService(rdbc); var client = clientService.GetClient(order.ClientId); var newOrder = new Order { ClientId = client.Id, ClientFirstName = client.FirstName, ClientLastName = client.LastName, ClientCountry = client.Country, Payments = new List<Payment> { new Payment { Amount = order.PaymentAmount, Id = order.PaymentId } }, Products = new List<Product> { new Product { Name = order.ProductName, Price = order.ProductPrice } }, TimeOfOrder = DateTime.Now }; orderService.AddOrder(newOrder); } return RedirectToAction("Index", "Home"); }
public OrderService(RavenDbConnection rdbc) { _ravenDbConnection = rdbc; }
public ClientService(RavenDbConnection ravenDbConnection) { _ravenDbConnection = ravenDbConnection; initDictCountriesRegions(); }
public ActionResult AddPayment(AddPaymentViewModel newPayment) { using (var rdbc = new RavenDbConnection(_rdcm)) { var orderService = new OrderService(rdbc); orderService.AddPayment(newPayment.OrderId, newPayment.PaymentId, newPayment.PaymentAmount); } return RedirectToAction("Index", "Orders"); }
// // GET: /Orders/ public ActionResult Index(int pageNumber = 1, int itemsPerPage = 10) { if (pageNumber < 1) pageNumber = 1; if (itemsPerPage < 1) itemsPerPage = 1; using (var rdbc = new RavenDbConnection(_rdcm)) { var orderService = new OrderService(rdbc); var orders = orderService.GetOrders(pageNumber, itemsPerPage); var viewModel = new OrdersHomeViewModel { CurrentPage = pageNumber, ItemsPerPage = itemsPerPage, Orders = orders.ToList() }; return View(viewModel); } }
// // GET: /Orders/DeleteOrder?orderId=1 public ActionResult DeleteOrder(string orderId) { using (var rdbc = new RavenDbConnection(_rdcm)) { var orderService = new OrderService(rdbc); orderService.DeleteOrder(orderId); } return RedirectToAction("Index"); }
public ActionResult AddProduct(AddProductViewModel newProduct) { using (var rdbc = new RavenDbConnection(_rdcm)) { var orderService = new OrderService(rdbc); orderService.AddProduct(newProduct.OrderId, newProduct.ProductName, newProduct.ProductPrice); } return RedirectToAction("Index", "Orders"); }
public static List<DummyOrder> RandomDummyOrders(int nrOrders, RavenDbConnection dbConnection) { var result = new List<DummyOrder>(); DateTime time = _start.AddDays(gen.Next(range)); var clientsList = dbConnection.GetClients(1, 15).Results; for (int i = 0; i < nrOrders; ++i) { var client = clientsList[gen.Next(clientsList.Count)]; result.Add(new DummyOrder(client.Id, client.FirstName, client.LastName, client.Country, null, null, DateTime.Now)); } foreach (var order in result) { int nrProducts = gen.Next(1, 5); for (int i = 0; i < nrProducts; ++i) order.AddProduct(_products[gen.Next(_products.Count)], Math.Round(gen.NextDouble() * 300,2)); int bankId = gen.Next(_banks.Count()); order.AddPayment(_banks[bankId] + "/" + (++_transactions[bankId]), Math.Round(gen.NextDouble() * -order.Balance,2)); order.AddPayment(_banks[bankId] + "/" + (++_transactions[bankId]), Math.Round(gen.NextDouble() * -order.Balance,2)); } return result; }
private static void Main(string[] args) { var manager = new ConnectionManager(); var dbConnector = new RavenDbConnection(manager); const bool _populating = false; const int _nrClients = 100000; const bool _reading = true; const int _page = 6; const int _itemsPerPage = 10000; const bool _deleting = false; const bool _order = false; #region Populate ClientsDB if (_populating) { var clients = RandomClients(_nrClients); DateTime time = _start.AddDays(gen.Next(range)); dbConnector.AddClients(clients); } #endregion #region Reading the data base if (_reading) { ShardedResults<Client> list = dbConnector.GetClients(_page, _itemsPerPage); foreach (var client in list.Results) { Console.WriteLine(client.ToString()); } if (list.ErrorConnectionStrings.Count > 0) { Console.WriteLine("Failed Connections"); foreach (var conectionStringName in list.ErrorConnectionStrings) { Console.WriteLine(conectionStringName); } } } #endregion #region Clearing the data base if (_deleting) { //ShardedResults<Client> list = dbConnector.GetClients(_page, _itemsPerPage); dbConnector.DeleteAllClients(); } #endregion #region Simulating several orders if (_order) { var order = new Order("Rest/clients/671603", "Albert", "Solberg", "Norway", null, null, DateTime.Now); order.AddProduct("Mouse", 15.50); order.AddProduct("Cable", 3.25); order.AddPayment("PKO-01", 17.75); dbConnector.AddOrder(order); } //var orderList = RandomOrders(90000,dbConnector); //dbConnector.AddOrders(orderList); var example = dbConnector.GetOrder("orders/250000"); //var olist = dbConnector.GetOrders(2, 15); //dbConnector.DeleteAllOrders(); #endregion Console.Write("End of program. Press any key to exit the application..."); Console.ReadKey(); }