private List <ProductLinkModel> GetListOfProductLinks(ProductLinkModel productLink, List <ProductLinkModel> searchResultProductLinks) { searchResultProductLinks = SqliteDAProductLink.GetAllProductLinks(productLink); return(searchResultProductLinks); }
// 2. Existing Product Link Initialize public ProductLinkNewOrEdit(int productLinkId) { InitializeComponent(); this.existingProductLink = SqliteDAProductLink.GetProductLinkById(productLinkId); formTitleLabel.Text = "Edit Product Link"; saveButton.Text = "Edit"; this.newProductLink = false; }
private void SearchForProductLinks() { ProductLinkModel productLink = new ProductLinkModel(); List <ProductLinkModel> searchResultProductLinks = new List <ProductLinkModel>(); productLink = SetProductLinkSearchTerm(productLink); searchResultProductLinks = GetListOfProductLinks(productLink, searchResultProductLinks); PopulateDGVWithSearchResults(searchResultProductLinks); }
private ProductLinkModel GetProductLink(ProductLinkModel productLink) { // Get Product Link Id from selected row in data grid view int productLinkId = 0; productLinkId = Convert.ToInt32(findProductLinkDataGridView.CurrentRow.Cells["Id"].Value); productLink = SqliteDAProductLink.GetProductLinkById(productLinkId); return(productLink); }
public ProductLinkModel AddProductLink(ProductLinkModel productLinkModel) { var productLink = mapper.Map <ProductLink>(productLinkModel); productLink.CreatedDate = DateTime.UtcNow; var addedEntity = dBContext.ProductLinks.Add(productLink); dBContext.SaveChanges(); return(addedEntity.Entity.ToModel <ProductLinkModel>(mapper)); }
public ProductLinkModel AddProductLink(ProductLinkModel productLinkModel) { var productLink = mapper.Map <ProductLink>(productLinkModel); productLink.Product = dBContext.Products.Find(productLinkModel.ProductId); var addedEntity = dBContext.ProductLinks.Add(productLink); dBContext.SaveChanges(); return(addedEntity.Entity.ToModel <ProductLinkModel>(mapper)); }
private void DisplaySelectedProductLink(ProductLinkModel productLink) { detailCategoryLabel2.Text = productLink.CategoryName; detailMeasurementRateLabel2.Text = productLink.MeasurementRate.ToString(); detailProductLinkNameLabel2.Text = productLink.Name; detailUnitOfMeasureLabel2.Text = productLink.UoM; detailWeightedLabel2.Text = productLink.Weighted; detailProductLinkIdLabel2.Text = productLink.Id.ToString(); uomLabel.Text = productLink.UoM; productLinkTabControl.SelectedTab = detailTabPage; }
protected async Task LoadFile(IFileListEntry file) { file.OnDataRead += (sender, eventArgs) => InvokeAsync(StateHasChanged); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/uploads", file.Name); var model = new ProductLinkModel() { Address = file.Name, Type = file.Type, ProductId = Item.Id }; /* * var endpoint = "<yourEndpoint>"; * var accessKeyId = "<yourAccessKeyId>"; * var accessKeySecret = "<yourAccessKeySecret>"; * var bucketName = "<yourBucketName>"; * var objectName = "<yourObjectName>"; * var objectContent = "More than just cloud."; * // Create an OSSClient instance. * var client = new OssClient(endpoint, accessKeyId, accessKeySecret); * try * { * byte[] binaryData = Encoding.ASCII.GetBytes(objectContent); * MemoryStream requestContent = new MemoryStream(5); * // Upload a file. * client.PutObject(bucketName, objectName, requestContent); * Console.WriteLine("Put object succeeded"); * } * catch (Exception ex) * { * Console.WriteLine("Put object failed, {0}", ex.Message); * } */ if (await ProductLinkService.PostProductLinkAsync(model) != null) { using (var stream = new FileStream(path, FileMode.Create)) { var ms = new MemoryStream(); await file.Data.CopyToAsync(stream); } Item.ProductLinks.Add(model); GlobalMsg.SetMessage("File " + file.Name + " uploaded.", MessageLevel.Error); } else { GlobalMsg.SetMessage("Failed to connect API.", MessageLevel.Error); } }
private ProductLinkModel SetProductLinkSearchTerm(ProductLinkModel productLink) { productLink.Name = findProductLinkNameTextBox.Text; productLink.CategoryName = findCategoryComboBox.Text; if (findWeightedCheckBox.CheckState == CheckState.Checked) { productLink.Weighted = "Weighted"; } else if (findWeightedCheckBox.CheckState == CheckState.Unchecked) { productLink.Weighted = "Pre-Packaged"; } return(productLink); }
private void SetProductLink() { if (findProductLinkDataGridView.SelectedRows.Count > 0) { ProductLinkModel productLink = new ProductLinkModel(); productLink = GetProductLink(productLink); DisplaySelectedProductLink(productLink); productGroupBox.Enabled = true; ActiveControl = productDescriptionTextBox; } else { MessageBox.Show("First select a product link in the table below before clicking select", "Price Link Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private ProductLinkModel SaveProductLinkToDb(ProductLinkModel productLink) { int productLinkId = SqliteDAProductLink.SaveProductLink(productLink); if (productLinkId > 0) { MessageBox.Show("New product link created successfully", "New Product Link", MessageBoxButtons.OK, MessageBoxIcon.Information); productLink.Id = productLinkId; } else { MessageBox.Show("Something went wrong. New product link could not be saved.\nCheck the error log for more information.", "New Product Link Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(productLink); }
// Other Event Methods //****************************************************************************************************** // Change Unit of measure label according to the selected product link's uom value. private void productLinkComboBox_SelectedValueChanged(object sender, EventArgs e) { //look for a product link object by the combobox's value if (productLinkComboBox.Items.Count > 0) { if (Int32.TryParse(productLinkComboBox.SelectedValue.ToString(), out int number)) { ProductLinkModel productLink = new ProductLinkModel(); productLink = SqliteDAProductLink.GetProductLinkById(number); //change the uom label text value to product link object's uom uomLabel.Text = productLink.UoM.ToString(); } else { uomLabel.Text = ""; } } }
// This checks whether the user's input is valid before committing anything to the database. private bool ValidateProductLinkInformation(ProductLinkModel productLink) { // Validate my data and save in the results variable ProductLinkValidator productLinkValidator = new ProductLinkValidator(); var results = productLinkValidator.Validate(productLink); // Check if the validator found any validation errors. if (results.IsValid == false) { foreach (ValidationFailure failure in results.Errors) { MessageBox.Show($"{ failure.ErrorMessage }", "Product Link Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); } else { return(true); } }
public async Task <ProductLinkModel> PostProductLinkAsync(ProductLinkModel productLinkModel) { try { var linkJson = new StringContent(JsonSerializer.Serialize(productLinkModel), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("api/ProductLink", linkJson); if (response.IsSuccessStatusCode) { return(await JsonSerializer.DeserializeAsync <ProductLinkModel>(await response.Content.ReadAsStreamAsync())); } return(null); } catch (Exception ex) { throw ex; } }
public IActionResult CreateEmployee([FromBody] ProductLinkModel productLinkModel) { if (productLinkModel == null) { return(BadRequest()); } if (productLinkModel.Address == string.Empty || productLinkModel.Type == string.Empty) { ModelState.AddModelError("link address and type", "The address and type shouldn't be empty"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdLink = repo.AddProductLink(productLinkModel); return(Created("productLink", createdLink)); }
private ProductLinkModel SetNewProductLinkInformation(ProductLinkModel productLink) { productLink.CategoryId = Convert.ToInt32(newCategoryComboBox.SelectedValue); productLink.CategoryName = newCategoryComboBox.Text; if (int.TryParse(newMeasurementRateTextBox.Text, out int result)) { productLink.MeasurementRate = result; } productLink.Name = newProductLinkNameTextBox.Text; productLink.UoM = newUomComboBox.Text; if (newWeightedCheckBox.CheckState == CheckState.Checked) { productLink.Weighted = "Weighted"; } else if (newWeightedCheckBox.CheckState == CheckState.Unchecked) { productLink.Weighted = "Pre-Packaged"; } return(productLink); }
private void SaveNewProductLinkToDb() { ProductLinkModel productLink = new ProductLinkModel(); productLink = SetNewProductLinkInformation(productLink); if (ValidateProductLinkInformation(productLink) == true) { productLink = SaveProductLinkToDb(productLink); } if (productLink.Id > 0) { DisplaySelectedProductLink(productLink); productGroupBox.Enabled = true; ActiveControl = productDescriptionTextBox; if (productLink.Weighted == "Weighted") { packSizeTextBox.Enabled = false; packSizeTextBox.Text = "1"; } } }
public IActionResult UploadFile([FromForm] UploadProductLinkModel model) { if (model == null) { return(BadRequest()); } if (model.ProductId == 0) { ModelState.AddModelError("ProductId", "ProductId shouldn't be zero"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var image = model.File; var endpoint = configuration.GetValue <string>("endpoint"); var accessKeyId = configuration.GetValue <string>("accessKeyId"); var accessKeySecret = configuration.GetValue <string>("accessKeySecret"); var bucketName = configuration.GetValue <string>("bucketName"); var objectName = Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName); // Create an OSSClient instance. var client = new OssClient(endpoint, accessKeyId, accessKeySecret); var stream = image.OpenReadStream(); // Upload a file. client.PutObject(bucketName, objectName, stream); var productLinkModel = new ProductLinkModel(); productLinkModel.ProductId = model.ProductId; productLinkModel.Name = objectName; productLinkModel.Type = Path.GetExtension(model.File.FileName); productLinkModel.Address = objectName; repo.AddProductLink(productLinkModel); return(Ok("https://nearnz.oss-ap-southeast-2.aliyuncs.com/" + objectName)); }