static void Setup() { string username = "******"; string password = "******"; string storename = "store"; LoginProxy service = new LoginProxy(); try { service.Register(username, password, DateTime.Now, "shit"); Console.WriteLine("Registering: " + username + ":" + password); Member member = service.loginEx(username, password); int storeId = service.AddStore(storename); Console.WriteLine("Opening store: " + storename + ":" + storeId); int product1Id = service.AddProductToStore(storeId, "product1", "testProduct", 10.0, "test"); service.AddProductToStock(storeId, product1Id, 10); Console.WriteLine("Adding product: " + "product1" + ":" + product1Id); int product2Id = service.AddProductToStore(storeId, "product2", "testProduct", 5.0, "test"); service.AddProductToStock(storeId, product1Id, 5); Console.WriteLine("Adding product: " + "product2" + ":" + product2Id); service.logout(); Console.WriteLine("Setup Done"); } catch (Exception e) { Console.WriteLine(e.Message); } }
private void addProductToStock(JObject msgObj, string message) { JsonResponse response; int requestId = (int)msgObj["id"]; int storeId = (int)msgObj["data"]["storeId"]; int productId = (int)msgObj["data"]["productId"]; int amount = (int)msgObj["data"]["amount"]; try { bool ans = user.AddProductToStock(storeId, productId, amount); if (ans) { response = JsonResponse.generateActionSucces(requestId); } else { response = JsonResponse.generateActionError(requestId, "can't add product to stock"); } } catch (WorkShopDbException dbExc) { response = JsonResponse.generateActionError(requestId, "DB is down please try again in few minutes\n" + dbExc.Message); } catch (Exception e) { response = JsonResponse.generateActionError(requestId, e.Message); } sendMyselfAMessage(JsonHandler.SerializeObject(response)); }