public string createSupplier() { Supplier resultSupplier = new Supplier(); GatewayResponse response = new GatewayResponse(); String s; try { s = new StreamReader(Request.InputStream).ReadToEnd(); resultSupplier = JsonConvert.DeserializeObject <Supplier>(s); } catch (Exception ex) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: When trying to parse JSON in server. " + ex.Message; return(JsonConvert.SerializeObject(response)); } SupplierCRUD supplierCRUD = new SupplierCRUD(); string idGenerated = supplierCRUD.createAndReturnIdGenerated(resultSupplier); if (supplierCRUD.ErrorOccur) { response.ErrorThrown = true; response.ResponseDescription = "ERROR: " + supplierCRUD.ErrorMessage; return(JsonConvert.SerializeObject(response)); } resultSupplier.Id = long.Parse(idGenerated); response.ErrorThrown = false; response.ResponseDescription = "Supplier created successfully."; response.Result = resultSupplier; return(JsonConvert.SerializeObject(response)); }
public void save() { Supplier supplier = new Supplier(); supplier.SupplierName = txtSupplierName.Text; supplier.ContactName = txtContactName.Text; supplier.ContactPhone = txtContactPhoneNumber.Text; supplier.ContactEmail = txtContactEmail.Text; supplier.ManufacturingLocation = txtManufacturingLocation.Text; supplier.ShipLocation = txtShipLocation.Text; supplier.QuotedCurrency = txtQuotedCurrency.Text; supplier.Capabilities = txtCapabilities.Text; supplier.Comments = txtComments.Text; supplier.Commodity = txtCommodity.Text; supplier.Visible = chkVisible.Checked; supplier.ContactCellPhone = txtContactCellPhone.Text; if (lblMode.Text == "New") { String idGenerated = supplierCRUD.createAndReturnIdGenerated(supplier); if (supplierCRUD.ErrorOccur) { Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCRUD.ErrorMessage); return; } supplier.Id = long.Parse(idGenerated); } else if (lblMode.Text == "Update") { supplier.Id = long.Parse(lblID.Text); if (!supplierCRUD.update(supplier)) { Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCRUD.ErrorMessage); return; } SupplierCommodityCRUD supplierCommodity_CRUD = new SupplierCommodityCRUD(); if (!supplierCommodity_CRUD.deleteByParentID(supplier.Id)) { Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCommodity_CRUD.ErrorMessage); return; } } List <Commodity> commoditiesList = uscCommodity.getEntity(); foreach (Commodity commodityLocal in commoditiesList) { Supplier_Commodity supplierCommodity = new Supplier_Commodity(); supplierCommodity.CommodityKey = commodityLocal.Id; supplierCommodity.SupplierKey = supplier.Id; if (!supplierCommodityCRUD.create(supplierCommodity)) { Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCommodityCRUD.ErrorMessage); return; } } uscNotifier.showSuccess("Information saved successfully"); AfterSave(this, null); }