public bool AddProductToService(License license, List <LicenseSet> licenseSets, Service service) { ServiceProduct sp = new ServiceProduct(); sp.LicenseId = license.LicenseId; sp.LicenseName = license.Name; sp.LicenseSets = new List <ServiceLicenseSet>(); foreach (var ls in licenseSets) { ServiceLicenseSet set = new ServiceLicenseSet(); set.LicenseId = license.LicenseId; set.LicenseSetId = ls.LicenseSetId; set.LicenseSetName = ls.Name; set.LicenseType = ls.SupportedLicenseTypes; set.MaxUsers = ls.MaxUsers; sp.LicenseSets.Add(set); } string mgmtToken = _packingService.PackToken(service.GetManagementToken()); AddProductResult result = _productsProvider.AddProduct(service.ManagementUrl, mgmtToken, GetManagementStandardEncryptionInfo(service), service.GetManagementServiceKeyPair(), sp); if (IsResultValid(result)) { return(true); } return(false); }
public string AddProduct(string token, string data) { AddProductResult result = new AddProductResult(); try { if (!_controlService.ValidateManagementToken(token)) { result.WasOperationSuccessful = false; return(_controlService.EncryptSymmetricResponse(_serializationProvider.Serialize(result))); } result.WasRequestValid = true; ServiceProduct product = _controlService.DeserializeAndDencryptMgmtInboundData <ServiceProduct>(data); _productManagementService.SaveServiceProduct(product); result.WasOperationSuccessful = true; } catch (Exception ex) { result.WasException = true; result.ExceptionMessage = ex.ToString(); } return(_controlService.SerializeAndEncryptMgmtOutboundData(result)); }
public string AddProduct(string token, string data) { AddProductResult result = new AddProductResult(); try { if (!_controlService.ValidateManagementToken(token)) { result.WasOperationSuccessful = false; return _controlService.EncryptSymmetricResponse(_serializationProvider.Serialize(result)); } result.WasRequestValid = true; ServiceProduct product = _controlService.DeserializeAndDencryptMgmtInboundData<ServiceProduct>(data); _productManagementService.SaveServiceProduct(product); result.WasOperationSuccessful = true; } catch (Exception ex) { result.WasException = true; result.ExceptionMessage = ex.ToString(); } return _controlService.SerializeAndEncryptMgmtOutboundData(result); }
public AddProductResult AddProduct(string url, string token, EncryptionInfo encryptionInfo, KeyPair serviceKeys, ServiceProduct product) { ProductsServiceClient client = ProductClientCreator(url); string encryptedToken = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo); string serializedPayload = _objectSerializationProvider.Serialize(product); string encryptedData = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, serviceKeys); string encryptedResult = client.AddProduct(encryptedToken, encryptedData); string decryptedResult = _asymmetricEncryptionProvider.DecryptPublic(encryptedResult, serviceKeys); AddProductResult result = _objectSerializationProvider.Deserialize <AddProductResult>(decryptedResult); return(result); }
private async void AddBtn_Clicked(object sender, EventArgs e) { if (!CommonLib.checkconnection()) { await App.Current.MainPage.Navigation.PushPopupAsync(new ShowMessage(AppResources._connection)); await Task.Delay(1000); ShowMessage.CloseAllPopup(); return; } var returnMessage = CheckValidations(); if (!string.IsNullOrEmpty(returnMessage)) { await App.Current.MainPage.Navigation.PushPopupAsync(new ShowMessage(returnMessage)); await Task.Delay(1000); ShowMessage.CloseAllPopup(); return; } try { LoggedInUser obj = App.Database.GetLoggedInUser(); await Navigation.PushPopupAsync(new Loader()); // string postData = "user_id=" + obj.userId + "&name=" + productNameTxt.Text + "&price=" + productPriceTxt.Text + "&description=" + productDetailTxt.Text + "&quantity=" + productquantityTxt.Text + "&prepare_time=" + producttimeTxt.Text + "&is_offer=" + is_offer; string postData = "user_id=" + obj.userId + "&name=" + productNameTxt.Text; HttpClient httpClient = new HttpClient(); string boundary = "---8d0f01e6b3b5dafaaadaad"; MultipartFormDataContent multipartContent = new MultipartFormDataContent(boundary); try { if (mysfile != null) { var fileContent = new ByteArrayContent(mysfile); fileContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/octet-stream"); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = "images[]", FileName = "userimage" + ".png", }; multipartContent.Add(fileContent); } } catch { } string url = CommonLib.ws_MainUrl + "addProduct?" + postData; HttpResponseMessage response = await httpClient.PostAsync(url, multipartContent); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); if (content != null) { mysfile = null; AddProductResult objData = new AddProductResult(); objData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddProductResult>(content); if (objData.status == 1) { Loader.CloseAllPopup(); AddAddonsViewModel.productId = objData.data.Product.id; EditProduct.id = ""; // await DisplayAlert("", objData.msg_ar, "OK"); await App.Current.MainPage.Navigation.PushAsync(new AddAddonsPage()); } else { Loader.CloseAllPopup(); if (App.Lng == "ar-AE") { await App.Current.MainPage.Navigation.PushPopupAsync(new ShowMessage(objData.msg_ar)); } else { await App.Current.MainPage.Navigation.PushPopupAsync(new ShowMessage(objData.msg_en)); } await Task.Delay(1000); ShowMessage.CloseAllPopup(); } } } else { Loader.CloseAllPopup(); await App.Current.MainPage.Navigation.PushPopupAsync(new ShowMessage("Upload 1 MB Image")); await Task.Delay(1000); ShowMessage.CloseAllPopup(); } } catch (Exception ex) { Loader.CloseAllPopup(); } }