public void PercentageDiscount_CalculateAppliedDiscount_HalfPriceDiscount() { var basket = new List <ProductQuantity>(); var discounts = new List <IDiscount>(); var product = new Product() { Id = 1, Name = "Apples", Price = 100m }; var productQuantity = new ProductQuantity() { Quantity = 1, Product = product }; basket.Add(productQuantity); var percentageDiscount = new HalfPriceDiscount(product, productQuantity); discounts.Add(percentageDiscount); var sut = new DiscountService(); // Act var result = sut.CalculateBasketDiscounts(basket, discounts); // Assert Assert.Equal(result.Any(), true); Assert.Equal(result[0].Type, DiscountType.HalfPrice); Assert.Equal(result[0].Amount, 50.00m); Assert.Equal(result[0].Description, "Apples 50% OFF: - 50p"); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductQuantityViewModel productQuantityVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var newQuantity = new ProductQuantity(); if (_productQuantityService.CheckExist(productQuantityVm.ProductId, productQuantityVm.SizeId, productQuantityVm.ColorId)) { return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Màu sắc kích thước cho sản phẩm này đã tồn tại"); } else { newQuantity.UpdateProductQuantity(productQuantityVm); _productQuantityService.Add(newQuantity); _productQuantityService.Save(); } } return response; })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,OrderId,ProductId,QtyProductOnOrder")] ProductQuantity productQuantity) { if (id != productQuantity.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productQuantity); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductQuantityExists(productQuantity.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["OrderId"] = new SelectList(_context.Order, "Id", "Id", productQuantity.OrderId); ViewData["ProductId"] = new SelectList(_context.Product, "Id", "Id", productQuantity.ProductId); return(View(productQuantity)); }
public void AddProductToOrderList(AddProductToOrderServiceModel model) { var order = this.data.Orders.Where(o => o.Id == model.OrderId).FirstOrDefault(); if (order == null) { throw new ArgumentException("There is no order whith given id."); } var product = this.data.Products.Where(p => p.Id == model.ProductId).FirstOrDefault(); if (product == null) { throw new ArgumentException("There is no product with given id."); } var productQuantity = new ProductQuantity { ProductId = model.ProductId, Product = product, Quantity = model.Quantity, }; order.ProductsQuantities.Add(productQuantity); this.data.SaveChanges(); }
public HttpResponseMessage Create(HttpRequestMessage request, ProductQuantityViewModel productQuantityVm) { if (ModelState.IsValid) { var newQuantity = new ProductQuantity(); try { if (_productQuantityService.CheckExist(productQuantityVm.ProductId, productQuantityVm.SizeId, productQuantityVm.ColorId)) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Màu sắc kích thước cho sản phẩm này đã tồn tại")); } else { newQuantity.UpdateProductQuantity(productQuantityVm); _productQuantityService.Add(newQuantity); _productQuantityService.Save(); return(request.CreateResponse(HttpStatusCode.OK, productQuantityVm)); } } catch (Exception dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public void Delete(int productId, int sizeId, int colorId) { ProductQuantity productQuantity = _produtQuantityRepository .FindSingle(x => x.ProductId == productId && x.SizeId == sizeId && x.ColorId == colorId); _produtQuantityRepository.Remove(productQuantity); }
//private void GetRoleList() //{ // string[] roleList = { "Admin", "Staff" }; // cbRoleList.ItemsSource = roleList; //} //private async void GetActiveBranchList() //{ // try // { // dynamic param = new { page = 0 }; // RootBranchObject Response = await ObjBranchService.BranchPostAPI("getBranchList", param); // if (Response.Status == "ok") // { // cbBranchList.ItemsSource = (Response.Data.OrderBy(property => property.Name).Select(item => item.Name)); // } // else // { // cbBranchList.Items.Add("- Fail to get branch list -"); // } // } // catch (Exception e) // { // cbBranchList.Items.Add("- Fail to get branch list -"); // } //} #endregion private void btnDialogOk_Click(object sender, RoutedEventArgs e) { if (tbPrice.Text == null && tbPrice.Text == "") { MessageBox.Show("Price cannot be empty", "UPO$$"); } else { ProductResult = new Product { Product_no = tbProductNo.Text, Name = tbName.Text, Category = tbCategory.Text, Design_code = tbDesignCode.Text, Colour_code = tbColourCode.Text, Price = Math.Round(Convert.ToDecimal(tbPrice.Text), 2, MidpointRounding.AwayFromZero).ToString("0.00") }; QuantityResult = new ProductQuantity { Branch_name = tbBranch.Text, Quantity = tbQuantity.Text }; this.DialogResult = true; } }
void BackEnd(bool isOwnerControl = false) { lbl_DiscountPrice.Visible = (ProductDiscountPercentage == 0) ? false : true; //Fill Variables lbl_ProductName.Text = ProductName; lbl_ProductTag.Text = ProductTag; pic_ProductImage.ImageLocation = ProductImagePath; lbl_ProductQuantity.Text = lbl_ProductQuantity_RS.Text = ProductQuantity.ToString(); lbl_ProductPrice.Text = lbl_DiscountPrice.Text = lbl_ProductPrice_RS.Text = Currency + " " + (ProductUnitPrice * ProductQuantity).ToString(); txt_DiscountPtg.Text = ProductDiscountPercentage.ToString(); double ProductAmount = (ProductUnitPrice * ProductQuantity); if (ProductDiscountPercentage != 0) { lbl_DiscountPrice.Text = Currency + " " + ProductAmount.ToString(); ProductTotalPrice = ProductAmount - (ProductDiscountPercentage / 100 * ProductAmount); } else { ProductTotalPrice = ProductAmount; } //Finally Update Price & % txt_DiscountPtg.Text = ProductDiscountPercentage.ToString(); lbl_ProductPrice.Text = lbl_ProductPrice_RS.Text = Currency + " " + ProductTotalPrice.ToString(); //Update Checkout Price Sell frmSell = (Sell)Application.OpenForms[FormName]; frmSell.UpdateCheckout(); }
public void FetchApplicableDiscountsTest() { ProductQuantity[] productQuantites = new ProductQuantity[0]; var applicableDiscounts = DiscountInfo.FetchApplicableDiscounts(productQuantites).ToArray(); Assert.IsTrue(applicableDiscounts.Length == 0); productQuantites = new ProductQuantity[] { new ProductQuantity(1, 2), new ProductQuantity(3, 1) }; applicableDiscounts = DiscountInfo.FetchApplicableDiscounts(productQuantites).ToArray(); Assert.IsTrue(applicableDiscounts.Length == 1); Assert.IsTrue(applicableDiscounts[0].Id == 1); productQuantites = new ProductQuantity[] { new ProductQuantity(1, 2), new ProductQuantity(2, 3) }; applicableDiscounts = DiscountInfo.FetchApplicableDiscounts(productQuantites).ToArray(); Assert.IsTrue(applicableDiscounts.Length == 2); productQuantites = new ProductQuantity[] { new ProductQuantity(3, 1), new ProductQuantity(2, 3) }; applicableDiscounts = DiscountInfo.FetchApplicableDiscounts(productQuantites).ToArray(); Assert.IsTrue(applicableDiscounts.Length == 1); Assert.IsTrue(applicableDiscounts[0].Id == 2); productQuantites = new ProductQuantity[] { new ProductQuantity(3, 1) }; applicableDiscounts = DiscountInfo.FetchApplicableDiscounts(productQuantites).ToArray(); Assert.IsTrue(applicableDiscounts.Length == 0); }
public IHttpActionResult PutProductQuantity(int id, ProductQuantity productQuantity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != productQuantity.ProductQuantityId) { return(BadRequest()); } db.Entry(productQuantity).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductQuantityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public HalfPriceDiscount( ProductQuantity productsThatQualifyForDiscount, DiscountedProduct discountProduct) { _productsThatQualifyForDiscount = productsThatQualifyForDiscount ?? throw new ArgumentNullException(nameof(productsThatQualifyForDiscount)); _discountProduct = discountProduct ?? throw new ArgumentNullException(nameof(discountProduct)); }
public ReceiptItem(ProductQuantity prodQuant, double unitPrice) { Product = prodQuant.Product; Quantity = prodQuant.Quantity; Price = unitPrice; TotalPrice = Quantity * Price; }
public ProductViewModel() { ObjProductService = new APIService(); _Path = "product"; GetActiveBranchList(); LoadStatusList(); searchCommand = new AsyncRelayCommand(Search, this); addCommand = new AsyncRelayCommand(Add, this); updateCommand = new AsyncRelayCommand(Update, this); //deleteCommand = new AsyncRelayCommand(Delete, this); restockCommand = new AsyncRelayCommand(Restock, this); activateCommand = new AsyncRelayCommand(Activate, this); deactivateCommand = new AsyncRelayCommand(Deactivate, this); previousPageCommand = new AsyncRelayCommand(PrevPage, this); nextPageCommand = new AsyncRelayCommand(NextPage, this); printBarcodeCommand = new AsyncRelayCommand(PrintBarcode, this); SelectedBranch = ""; SelectedStatus = "Active"; SelectedProduct = new Product(); SelectedQuantity = new ProductQuantity(); InputProduct = new Product(); Pagination = new Pagination { CurrentPage = 1, CurrentRecord = "0 - 0", TotalPage = 1, TotalRecord = 0 }; }
public static void UpdateProductQuantity(this ProductQuantity quantity, ProductQuantityViewModel quantityVm) { quantity.ColorId = quantityVm.ColorId; quantity.ProductId = quantityVm.ProductId; quantity.SizeId = quantityVm.SizeId; quantity.Quantity = quantityVm.Quantity; }
protected override ConditionImp VisitConditionElement(ProductQuantity info) { return(new ProductQuantityImp { From = info.From, To = info.To }); }
private void CheckQuantityAvailableForRevert(IIncomingProduct incoming) { ProductQuantity productQuantity = ProductQuantities .SingleOrDefault(p => p.Id == incoming.ProductId); InsufficientBalance = productQuantity == null || productQuantity.TotalAvailable < incoming.Quantity; }
private void CheckQuantityAvailableFor(IOutgoingProduct outgoing) { ProductQuantity productQuantity = ProductQuantities .SingleOrDefault(p => p.Id == outgoing.ProductId); InsufficientBalance = productQuantity == null || productQuantity.TotalAvailable < outgoing.Quantity; }
public async Task <IActionResult> Create([Bind("Id,OrderId,ProductId,QtyProductOnOrder")] ProductQuantity productQuantity) { productQuantity.OrderId = productQuantity.Id; productQuantity.Id = 0; if (ModelState.IsValid) { _context.Add(productQuantity); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } else { Dictionary <string, string> actionDict = new Dictionary <string, string>(); int ID = 0; Product newProd = new Product(); foreach (var product in _context.Product.ToList()) { if (product.Id == productQuantity.ProductId) { int temp = product.Quantity - productQuantity.QtyProductOnOrder; if (temp >= 0) { newProd = product; newProd.Quantity = temp; ID = product.Id; _context.Update(newProd); await _context.SaveChangesAsync(); _context.Add(productQuantity); await _context.SaveChangesAsync(); actionDict.Add(product.Title, "Product quantity decreased to " + product.Quantity + "&&"); if (newProd.MinThreshold >= newProd.Quantity) { actionDict.Add(Convert.ToString(newProd.Id) + " >> " + newProd.Title, "Product has reached or passed minimum threshold of " + newProd.MinThreshold + " and this product's quantity is now at " + newProd.Quantity + "&&"); } } else { actionDict.Add(product.Title, "Not enough of this product to make order. Product quantity not updated and product not added to order.&&"); } } } string temp2 = ""; foreach (var item in actionDict.Keys) { temp2 += item + " - " + actionDict[item]; } return(RedirectToAction("Result", new { id = ID, actionStr = temp2 })); } ViewData["OrderId"] = new SelectList(_context.Order, "Id", "OrderNumber", productQuantity.OrderId); ViewData["ProductId"] = new SelectList(_context.Product, "Id", "Title", productQuantity.ProductId); return(View(productQuantity)); }
public async Task UpdateProductQuantity(int id, ProductQuantity productQuantity) { using var context = new HomeAppDbContext(myDbOptions); var productToChange = context.ProductQuantities.FirstOrDefault(q => q.Id == id); productToChange.UnitQuantity = productQuantity.Quantity; await context.SaveChangesAsync(); }
public static bool Delete(ProductQuantity productQuantity) { using (_d = new DataRepository <ProductQuantity>()) { _d.Delete(productQuantity); _d.SaveChanges(); } return(true); }
public TransferResponse Execute(TransferRequest model) { var toSiteId = _translator.TranslateStoreIdToSiteId(model.ToStore.StoreId); var fromSiteId = _translator.TranslateStoreIdToSiteId(model.FromStore.StoreId); var tr = new Transfer(); List <InventoryQuantity> availableToSell = _omsService.GetAvailableToSellInventory(new InventorySearchFilter() { StoreIds = new List <string>() { toSiteId, fromSiteId } }); var transferred = new List <ProductQuantity>(); foreach (var p in model.ProductsToTransfer) { var decrementQuantity = new ProductQuantity(p, p.Quantity * -1); var inventoryTransferred = availableToSell.FirstOrDefault(iq => iq.Product.UPC == p.UPC); _omsService.UpdateAvailableInventory(new UpdateInventoryRequest() { Quantity = decrementQuantity, SiteId = fromSiteId }); _omsService.UpdateAvailableInventory(new UpdateInventoryRequest() { Quantity = p, SiteId = toSiteId }); transferred.Add(p); } switch (model.TransferType) { case TransferType.PurchaseOrder: if (model.FromLocation.LocationId != model.ToLocation.LocationId) { //Create PO in warehouse } break; case TransferType.ReturnToVendor: //Create RTV in warehouse break; default: throw new InvalidOperationException(); } return(new TransferResponse() { QuantitiesTransferred = transferred }); }
public override int GetHashCode() { var hashCode = -2027619230; hashCode = hashCode * -1521134295 + ProductID.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(ProductName); hashCode = hashCode * -1521134295 + ProductPrice.GetHashCode(); hashCode = hashCode * -1521134295 + ProductQuantity.GetHashCode(); return(hashCode); }
public ProductQuantity ConvertProductViewModelToProductQuantity(ProductViewModel product) { var model = new ProductQuantity() { Quantity = product.Quantity, ProductId = product.ProductId, Id = product.Id }; return(model); }
public string SaveQuantity(ProductQuantity productQuantity) { if (aQuantityGateway.SaveQuantity(productQuantity) > 0) { return("Product Quantity has been saved successfully"); } else { return("Failed to save Product Quantity"); } }
private void ProductID_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && this.ProductID.Text != "" && this.ProductQuantity.Text != "") { add.PerformClick(); } if (e.KeyCode == Keys.Tab && this.ProductID.Text != "") { ProductQuantity.Focus(); } }
public IHttpActionResult GetProductQuantity(int id) { ProductQuantity productQuantity = db.ProductQuantities.Find(id); if (productQuantity == null) { return(NotFound()); } return(Ok(productQuantity)); }
public async Task AddProductToBasket(Product product, ProductQuantity qty) { await Task.CompletedTask; /* * Do any db checks & validation checks */ //if successful rais event that item was added RaiseEvent(new ProductAddedToShoppingCart(product, qty)); }
public bool CastVariables() { try { ProductIDs.AddRange(ProductIDsText.Split(',').Select(s => int.Parse(s))); ProductQuantity.AddRange(ProductQuantityText.Split(',').Select(s => int.Parse(s))); }catch (Exception ex) { return(false); } return(true); }
public IHttpActionResult PostProductQuantity(ProductQuantity productQuantity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ProductQuantities.Add(productQuantity); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = productQuantity.ProductQuantityId }, productQuantity)); }
public async Task <IActionResult> Put(int id, [FromBody] ProductQuantity productQuantity) { try { await myProductService.UpdateProductQuantity(id, productQuantity); } catch (Exception e) { return(BadRequest()); } return(Ok()); }