internal static bool createJSON() { JSONFormat jsformat = new JSONFormat { EnableDiscord = true, DiscordUsername = "******", DiscordAvatar = "<Add the url to the avatar of your webhook here>", DiscordApid = new string[] { "<Add your webhook ID's here seperated by commas>", "<Example ID 1>", "<Example ID 2>" }, DiscordApikey = new string[] { "<Add your webhook private keys here seperated by commas>", "<Example Private Key 1>", "<Example Private Key 2>" }, DiscordChannels = new string[] { "<Add your webhook channels here seperated by commas>", "<Example Channel 1>", "<Example Channel 2>" }, EnableMysql = true, MysqlUsername = "******", MysqlPassword = "******", MysqlServerAddress = "<Add the IP to your Mysql server here>", MysqlServerPort = 3306, MysqlDatabase = "<Name of the database you want to access>", EnableDebug = false }; var serialiser = new JsonSerializer(); using (var sw = new StreamWriter(CfgJson, false)) using (var jsw = new JsonTextWriter(sw)) { serialiser.Formatting = Formatting.Indented; serialiser.Serialize(jsw, jsformat); } Session.LogThis("[AEX::JSON] Created config.json in cfg directory."); return(true); }
public static object readJSON(string module, string attrib) { if (!(Directory.Exists(CfgDir))) { Session.LogThis("[AEX::JSON] Config directory missing, creating a new directory."); Directory.CreateDirectory(CfgDir); } if (!(File.Exists(CfgJson))) { Session.LogThis("[AEX::JSON] Readable file not found, creating a new json file. Please configure this otherwise the extension will not work."); createJSON(); } JSONFormat ds = null; try { ds = JsonConvert.DeserializeObject <JSONFormat>(File.ReadAllText(CfgDir + @"\config.json")); } catch (EntryPointNotFoundException e) { createJSON(); System.Threading.Thread.Sleep(1000); readJSON(module, attrib); } if (module == "discord") { if (Discord.ModuleActivated == false) { return("ERR_INVALID_MODULE_DISCORD"); } switch (attrib) { case "username": return(ds.DiscordUsername); case "avatar": return(ds.DiscordAvatar); case "apid": return(ds.DiscordApid); case "apikey": return(ds.DiscordApikey); case "enable": return(ds.EnableDiscord); default: return("ERR_INVALID_ATTRIB"); } } else if (module == "mysql") { if (Mysql.ModuleActivated == false) { return("ERR_INVALID_MODULE_MYSQL"); } switch (attrib) { case "username": return(ds.MysqlUsername); case "password": return(ds.MysqlPassword); case "address": return(ds.MysqlServerAddress); case "port": return(ds.MysqlServerPort); case "database": return(ds.MysqlDatabase); case "buffer": return(ds.MysqlBufferSize); case "enable": return(ds.EnableMysql); default: return("ERR_INVALID_ATTRIB"); } } else if (module == "misc") { switch (attrib) { case "datamaxreturn": return(ds.DataMaxReturnSize); case "enabledebug": return(ds.EnableDebug); } } return("ERR_INVALID_PARAMS"); }
public static object[] readJSONArray(string module, string attrib) { if (!(Directory.Exists(CfgDir))) { Session.LogThis("[AEX::JSON] Config directory missing, creating a new directory."); Directory.CreateDirectory(CfgDir); } if (!(File.Exists(CfgJson))) { Session.LogThis("[AEX::JSON] Readable file not found, creating a new json file. Please configure this otherwise the extension will not work."); createJSON(); } JSONFormat ds = null; try { ds = JsonConvert.DeserializeObject <JSONFormat>(File.ReadAllText(CfgDir + @"\config.json")); } catch (EntryPointNotFoundException e) { createJSON(); System.Threading.Thread.Sleep(1000); readJSON(module, attrib); } if (module == "discord") { if (Discord.ModuleActivated == false) { return(new string[1] { "ERR_INVALID_MODULE_DISCORD" }); } switch (attrib) { case "apid": return(ds.DiscordApid); case "apikey": return(ds.DiscordApikey); case "channels": return(ds.DiscordChannels); default: return(new string[1] { "ERR_INVALID_ATTRIB" }); } } else if (module == "mysql") { if (Mysql.ModuleActivated == false) { return(new string[1] { "ERR_INVALID_MODULE_MYSQL" }); } switch (attrib) { default: return(new string[1] { "ERR_INVALID_ATTRIB" }); } } return(new string[1] { "ERR_INVALID_PARAMS" }); }
public ObjectSelectionFormat(string compressionType, CSVFormat csv) { this.compressionType = compressionType; this.csvFormat = csv; this.jsonFormat = null; }
public ObjectSelectionFormat(string compressionType, JSONFormat json) { this.compressionType = compressionType; this.csvFormat = null; this.jsonFormat = json; }
public JSONFormat <List <ProductViewModel> > GetAllProducts() { JSONFormat <List <ProductViewModel> > result = null; //create productViewModel List to return for client List <ProductViewModel> productList = new List <ProductViewModel>(); try { //get all cateogories var categories = categoryRepository.All().Where(c => c.Active == true).ToList(); for (int i = 0; i < categories.Count; i++) { int cateID = categories[i].ID; //get all products of category var products = productRepository.GetAllProducts() .Where(q => q.CategoryID == cateID) .Where(q => q.Active == true).ToList(); if (products != null) { for (int j = 0; j < products.Count; j++) { //get product skus by productID int proID = products[j].ID; var productSkus = productSkuRepository.All() .Where(p => p.ProductID == proID) .Where(p => p.Active == true).ToList(); var proImageList = imageRepository.All(). Where(p => p.ProductID == proID).ToList(); List <string> imageList = new List <string>(); foreach (ProductImage item in proImageList) { imageList.Add(item.PicURL.ToString()); } if (productSkus != null) { //add products sku to product sku model List <ProductSkuViewModel> proSkus = new List <ProductSkuViewModel>(); foreach (ProductSku sku in productSkus) { //add productSkuViewModel to a product proSkus.Add(new ProductSkuViewModel() { ID = sku.ID, ProductID = sku.ProductID, Size = sku.Size, UnitPrice = sku.UnitPrice }); }//end for productSku productList.Add(new ProductViewModel() { ID = products[j].ID, Name = products[j].Name, Description = products[j].Description, imageList = imageList, ProductSkus = proSkus }); } //end if productSkus } //end for product } } result = new JSONFormat <List <ProductViewModel> > { status = new Status { success = true, message = ConstantManager.MES_GET_PRODUCT_SUCCESS, status = ConstantManager.STATUS_SUCCESS }, data = productList }; return(result); } catch (Exception ex) { result = new JSONFormat <List <ProductViewModel> > { status = new Status { success = false, message = ex.Message, status = ConstantManager.STT_FAIL }, data = null }; } return(result); }
public JSONFormat <List <OrderViewModel> > OrderHistory([FromBody] LoginViewModel loginViewModel) { JSONFormat <List <OrderViewModel> > result = null; List <OrderViewModel> orderViewModelList = new List <OrderViewModel>(); string customerId = Utilities.getCustomerIDFromToken(loginViewModel.accessToken); Customer existedCustomer = customerRepository.Find(customerId); try { if (existedCustomer != null) { var orderHistoryList = orderRepository.All().Where(p => p.CustomerID == customerId); if (orderHistoryList != null) { foreach (var order in orderHistoryList) { OrderViewModel orderViewModel = new OrderViewModel(); orderViewModel.OrderId = order.ID; orderViewModel.OrderTime = order.CreatedDate.ToString(); orderViewModel.Status = order.Status; orderViewModel.AccessToken = loginViewModel.accessToken; orderViewModel.ShippingAddress = order.ShippingAddress; orderViewModel.PaymentType = order.Payment; orderViewModel.Note = order.Note; double totalAmount = 0; List <OrderDetailViewModel> orderDetailViewModelList = new List <OrderDetailViewModel>(); var orderDetaiList = orderDetailRepository.All().Where(p => p.OrderID == order.ID); if (orderDetaiList != null) { foreach (var item in orderDetaiList) { int productSkuID = item.ProductSkuID; ProductSku productSku = productSkuRepository.Find(p => p.ID == productSkuID); double size = productSku.Size.Value; int parentProId = productSku.ProductID; Product parentProduct = productRepository.Find(p => p.ID == parentProId); string name = parentProduct.Name; string imageURL = imageRepository.All().Where(p => p.ProductID == parentProId).First().PicURL.ToString(); OrderDetailViewModel orderDetail = new OrderDetailViewModel(); orderDetail.ProductSkuID = productSkuID; orderDetail.imageURL = imageURL; orderDetail.Name = name; orderDetail.Size = size; orderDetail.UnitPrice = item.UnitPrice; orderDetail.Quantity = item.Quantity; orderDetailViewModelList.Add(orderDetail); totalAmount += item.Quantity * item.UnitPrice; } } orderViewModel.TotalAmount = totalAmount; orderViewModel.OrderDetailList = orderDetailViewModelList; orderViewModelList.Add(orderViewModel); } result = new JSONFormat <List <OrderViewModel> > { status = new Status() { success = true, message = ConstantManager.MES_GET_ORDER_SUCCESS, status = ConstantManager.STATUS_SUCCESS }, data = orderViewModelList }; } } else { result = new JSONFormat <List <OrderViewModel> > { status = new Status() { success = false, message = ConstantManager.MES_GET_ORDER_FAIL, status = ConstantManager.STT_FAIL }, data = null }; } } catch (Exception ex) { result = new JSONFormat <List <OrderViewModel> > { status = new Status() { success = false, message = ConstantManager.MES_GET_ORDER_FAIL, status = ConstantManager.STT_FAIL }, data = null }; } return(result); }
public JSONFormat <OrderSuccessViewModel> SetOrder([FromBody] OrderViewModel orderViewModel) { JSONFormat <OrderSuccessViewModel> result = null; try { string customerID = Utilities.getCustomerIDFromToken(orderViewModel.AccessToken); Customer existedCustomer = customerRepository.Find(customerID); if (existedCustomer != null) { //insert order to DB Order order = new Order(); order.CustomerID = customerID; order.CreatedDate = DateTime.Now; order.ShippingAddress = orderViewModel.ShippingAddress; order.ShippingFee = 0; if (orderViewModel.PaymentType == "CASH") { order.Payment = "COD"; } else { order.Payment = "Other payment"; } order.Note = orderViewModel.Note; order.Status = 1; Order insertedOrder = orderRepository.Create(order); //insert orderDetail List <OrderDetailViewModel> orderDetailList = orderViewModel.OrderDetailList; foreach (OrderDetailViewModel item in orderDetailList) { OrderDetail orderDetail = new OrderDetail(); orderDetail.OrderID = insertedOrder.ID; orderDetail.ProductSkuID = item.ProductSkuID; orderDetail.Quantity = item.Quantity; orderDetail.UnitPrice = item.UnitPrice; orderDetailRepository.Create(orderDetail); } //return result for client result = new JSONFormat <OrderSuccessViewModel> { status = new Status() { success = true, message = ConstantManager.MES_SET_ORDER_SUCCESS, status = ConstantManager.STATUS_SUCCESS } }; } } catch (Exception ex) { result = new JSONFormat <OrderSuccessViewModel> { status = new Status() { success = false, message = ConstantManager.MES_SET_ORDER_FAIL, status = ConstantManager.STT_FAIL } }; } return(result); }
public JSONFormat <CustomerViewModel> LoginByPhone([FromBody] LoginViewModel loginModel) { JSONFormat <CustomerViewModel> result; var customerInfoJson = GetPhoneFromFacebook(loginModel.accessToken); try { var parsedObject = JObject.Parse(customerInfoJson); var phone = parsedObject["phone"]["number"].ToString(); var id = parsedObject["id"].ToString(); Customer existedCustomer = customerRepository.Find(c => c.ID == id); CustomerViewModel customerModel = null; if (existedCustomer == null) { Customer customerDB = new Customer { ID = id, Phone = phone }; Customer createdCustomer = customerRepository.Create(customerDB); if (createdCustomer != null) { string clientToken = Utilities.GenerateToken(id); customerModel = new CustomerViewModel { access_token = clientToken, phone = phone, first_login = true }; } } else { string clientToken = Utilities.GenerateToken(id); customerModel = new CustomerViewModel { access_token = clientToken, name = existedCustomer.Name, phone = phone, first_login = false, email = existedCustomer.Email, address = existedCustomer.Address }; } if (customerModel != null) { result = new JSONFormat <CustomerViewModel> { status = new Status { success = true, message = ConstantManager.MES_LOGIN_SUCCESS, status = ConstantManager.STATUS_SUCCESS }, data = customerModel }; return(result); } } catch (Exception ex) { Console.WriteLine(ex.Message); } result = new JSONFormat <CustomerViewModel> { status = new Status { success = false, message = ConstantManager.MES_LOGIN_FAIL, status = ConstantManager.STT_FAIL }, data = null }; return(result); }
public JSONFormat <CustomerViewModel> UpdateCustomer([FromBody] CustomerViewModel customer) { JSONFormat <CustomerViewModel> result; try { if (customer != null) { string accessToken = customer.access_token; string customerID = Utilities.getCustomerIDFromToken(accessToken); if (!customerID.Equals("")) { string address = ""; Customer cus; if (customer.address == null || customer.address.Length == 0) { Customer existedCus = customerRepository.Find(c => c.ID == customerID); address = existedCus.Address; cus = new Customer { ID = customerID, Name = customer.name, Email = customer.email, Address = address }; } else { cus = new Customer { ID = customerID, Name = customer.name, Email = customer.email, Address = customer.address }; } bool update = customerRepository.updateCustomer(cus); if (update) { customer.first_login = false; result = new JSONFormat <CustomerViewModel> { status = new Status { success = true, message = ConstantManager.MES_UPDATE_SUCCESS, status = ConstantManager.STATUS_SUCCESS }, data = customer }; return(result); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } result = new JSONFormat <CustomerViewModel> { status = new Status { success = false, message = ConstantManager.MES_UPDATE_FAIL, status = ConstantManager.STT_FAIL }, data = null }; return(result); }