public void TestCreateSameSerialNumberProductUnitAsync() { ContextSeeder.Seed(); var braBo = new BrandBusinessObject(); var bra = new Brand("Barraca do Tejo"); braBo.Create(bra); var catBo = new CategoryBusinessObject(); var cat = new Category("Non-Alcoholic Beverages"); catBo.Create(cat); var pmbo = new ProductModelBusinessObject(); var prodMod = new ProductModel("Vinho Branco", "506-1237-422", "", 4.24, 0.80, Measure.L, bra.Id, cat.Id); pmbo.Create(prodMod); var sbo = new ShoppingBasketBusinessObject(); var sbk = sbo.ListNotDeleted().Result.First(); var bo = new ProductUnitBusinessObject(); var item = bo.ListAsync().Result.Result.FirstOrDefault(); var ebo = new EstablishmentBusinessObject(); var est = ebo.ListNotDeleted().Result.First(); var prodUnit = new ProductUnit(item.SerialNumber, false, prodMod.Id, est.Id, sbk.Id); var resCreate = bo.CreateAsync(prodUnit).Result; Assert.IsTrue(!resCreate.Result); }
public void UpdateProductDetails() { if (!ValidateProductDetails()) { return; } string barcode = m_UIControl.tf_ProductDetails_Barcode.Text.Trim(); if (CheckIfBarcodeAlreadyInUse(barcode)) { m_UIControl.lbl_Error.Text = "This Barcode is already in use!"; return; } string name = m_UIControl.tf_ProductDetails_ProductName.Text.Trim(); if (CheckIfProductNameAlreadyInUse(name)) { m_UIControl.lbl_Error.Text = "This Name is already in use!"; return; } ProductGet existingProduct = m_Product; ProductPost product = new ProductPost(existingProduct); product.ID = int.Parse(m_UIControl.tf_ProductDetails_ProductID.Text.Trim()); product.Barcode = barcode; product.Name = name; product.Description = m_UIControl.tf_ProductDetails_Description.Text.Trim(); product.Unit = ProductUnit.GetUnitFromText(m_UIControl.cb_Unit.Text); product.RetailPrice = int.Parse(m_UIControl.tf_ProductDetails_RetailPrice.Text.Trim()); product.WholeSalePrice = int.Parse(m_UIControl.tf_ProductDetails_WholesalePrice.Text.Trim()); product.Discount = double.Parse(m_UIControl.tf_ProductDetails_Discount.Text.Trim()); product.CGST = double.Parse(m_UIControl.tf_ProductDetails_CGST.Text.Trim()); product.SGST = double.Parse(m_UIControl.tf_ProductDetails_SGST.Text.Trim()); string categoryName = m_UIControl.cb_ProductDetails_Category.Text.Trim(); product.CategoryID = DataService.GetCategoryDataController().GetByName(categoryName).ID; bool imageModified = false; if (m_UIControl.pictureBox_ProductImage.Tag != null) { product.ImagePath = m_UIControl.pictureBox_ProductImage.Tag.ToString(); imageModified = true; } m_Product = DataService.GetProductDataController().Put(product, imageModified); string message = (m_Product == null) ? "Failed to Update Product Details!" : "Product Details updated successfully!"; MessageBox.Show(m_UIControl, message); // fire entry updated event Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.PRODUCT, m_Product.ID); EventBroadcaster.Get().BroadcastEvent(e); }
protected void cboProductUnit_SelectedIndexChanged(object sender, EventArgs e) { ProductPackage clsProductPackage = new ProductPackage(); ProductPackageDetails clsDetails = clsProductPackage.DetailsByProductIDAndUnitID(long.Parse(cboProductCode.SelectedValue), long.Parse(cboProductUnit.SelectedValue)); if (clsDetails.PackageID == 0) { ProductUnit clsProductUnit = new ProductUnit(clsProductPackage.Connection, clsProductPackage.Transaction); Products clsProduct = new Products(clsProductPackage.Connection, clsProductPackage.Transaction); ProductDetails clsProductDetails = clsProduct.Details(long.Parse(cboProductCode.SelectedItem.Value)); decimal decBaseUnitValue = clsProductUnit.GetBaseUnitValue(long.Parse(cboProductCode.SelectedItem.Value), int.Parse(cboProductUnit.SelectedItem.Value), 1); clsDetails.Price = decBaseUnitValue * clsProductDetails.Price; clsDetails.PurchasePrice = decBaseUnitValue * clsProductDetails.PurchasePrice; } clsProductPackage.CommitAndDispose(); txtPrice.Text = clsDetails.PurchasePrice.ToString("#####0.#0"); txtSellingPrice.Text = clsDetails.Price.ToString("#####0.#0"); txtOldSellingPrice.Text = clsDetails.Price.ToString("#####0.#0"); decimal decMargin = clsDetails.Price - clsDetails.PurchasePrice; try { decMargin = decMargin / clsDetails.PurchasePrice; } catch { decMargin = 1; } decMargin = decMargin * 100; txtMargin.Text = decMargin.ToString("#,##0.##0"); txtVAT.Text = clsDetails.VAT.ToString("#,##0.#0"); txtEVAT.Text = clsDetails.EVAT.ToString("#,##0.#0"); txtLocalTax.Text = clsDetails.LocalTax.ToString("#,##0.#0"); }
public void Given_BulkDiscountIsCreated_ThenReturnsBaseClassType() { var product = new ProductUnit("Book", 10.0m); var bulkDiscount = new BulkDiscount(product, "Buy 2 gets 1 free", 2, 1); Assert.IsAssignableFrom <Discount>(bulkDiscount); }
public void BatchDeleteTest() { ProductUnit v1 = new ProductUnit(); ProductUnit v2 = new ProductUnit(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v1.PUName = "4PBK"; v2.PUName = "Fwgq"; context.Set <ProductUnit>().Add(v1); context.Set <ProductUnit>().Add(v2); context.SaveChanges(); } var rv = _controller.BatchDelete(new string[] { v1.ID.ToString(), v2.ID.ToString() }); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data1 = context.Set <ProductUnit>().Find(v1.ID); var data2 = context.Set <ProductUnit>().Find(v2.ID); Assert.AreEqual(data1.IsValid, false); Assert.AreEqual(data2.IsValid, false); } rv = _controller.BatchDelete(new string[] {}); Assert.IsInstanceOfType(rv, typeof(OkResult)); }
private Results AddUnit() { var result = new Results(); try { var database = new InventoryEntities(); var count = (from c in database.ProductUnits where c.UnitName == txtUnit.Text.Trim() select c).FirstOrDefault(); if (count == null) { var unit = new ProductUnit(); unit.UnitName = txtUnit.Text.Trim(); result.Result = true; database.ProductUnits.Add(unit); database.SaveChanges(); result.Message = " New Unit Successfully Added !!! "; } else { result.Result = false; result.Message = "Unit Already Exist"; } return(result); } catch (Exception ex) { result.Result = false; result.Message = "Unknown Error"; return(result); } }
public static float GetStepperIncrement(this ProductUnit unit) { float stepperValue = 0.1f; switch (unit) { case ProductUnit.KiloGramm: case ProductUnit.Liter: stepperValue = .5f; break; case ProductUnit.Piece: case ProductUnit.Package: case ProductUnit.Can: case ProductUnit.Glas: case ProductUnit.Bottle: stepperValue = 1; break; case ProductUnit.Gramm: case ProductUnit.MilliLiter: stepperValue = 50f; break; } return(stepperValue); }
/// <summary> /// 添加 /// </summary> /// <param name="pro"></param> /// <returns></returns> public static int Add(ProductUnit pro) { PSSEntities db = new PSSEntities(); db.ProductUnit.Add(pro); return(db.SaveChanges()); }
/// <summary> /// 修改 /// </summary> /// <param name="pro"></param> /// <returns></returns> public static int Edit(ProductUnit pro) { PSSEntities db = new PSSEntities(); db.Entry <ProductUnit>(pro).State = System.Data.Entity.EntityState.Modified; return(db.SaveChanges()); }
public void EditTest() { ProductUnit v = new ProductUnit(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.PUName = "4PBK"; context.Set <ProductUnit>().Add(v); context.SaveChanges(); } ProductUnitVM vm = _controller.Wtm.CreateVM <ProductUnitVM>(); var oldID = v.ID; v = new ProductUnit(); v.ID = oldID; v.PUName = "Fwgq"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.PUName", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <ProductUnit>().Find(v.ID); Assert.AreEqual(data.PUName, "Fwgq"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public async Task <OperationResult <bool> > CreateAsync(ProductUnit item) { try { if (_dao.ListAsync().Result.Any(x => x.SerialNumber.ToLower().Trim() == item.SerialNumber.ToLower().Trim() && !x.IsDeleted)) { return new OperationResult <bool>() { Success = true, Result = false, Message = "Serial number already exists" } } ; await _dao.CreateAsync(item); return(new OperationResult <bool>() { Success = true, Result = true }); } catch (Exception e) { return(new OperationResult <bool>() { Success = false, Exception = e }); } }
public async Task <ActionResultResponse> Insert(ProductUnit productUnit) { var productInfo = await _productRepository.CheckExists(productUnit.ProductId, productUnit.TenantId); if (!productInfo) { return(new ActionResultResponse(-1, _sharedResourceService.GetString(ErrorMessage.NotExists, _resourceService.GetString("product")))); } // Kiểm tra đơn vị đã tồn tại chưa. var isExists = await _productUnitRepository.CheckExists(productUnit.TenantId, productUnit.ProductId, productUnit.UnitId); if (isExists) { return(new ActionResultResponse(-2, _sharedResourceService.GetString(ErrorMessage.AlreadyExists, _resourceService.GetString("unit")))); } if (productUnit.IsDefault) { // Kiểm tra đã tồn tại đơn vị mặc định chưa. var isDefaultUnitExists = await _productUnitRepository.CheckDefaultUnitExists(productUnit.ProductId, productUnit.TenantId); if (isDefaultUnitExists) { return(new ActionResultResponse(-3, _sharedResourceService.GetString(ErrorMessage.AlreadyExists, _resourceService.GetString("default unit")))); } } var result = await _productUnitRepository.Insert(productUnit); return(new ActionResultResponse(result, result <= 0 ? _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong) : _sharedResourceService.GetString(SuccessMessage.AddSuccessful, _resourceService.GetString("Product unit")))); }
public List <ProductUnit> AddUnits(int amount) { List <ProductUnit> units = new List <ProductUnit>(); float ySize = panelSize.y / onePageAmount; float contentYSize = panelSize.y; int totalAmount = nowAmount + amount; if (totalAmount > onePageAmount) { contentYSize = ySize * totalAmount; } content.offsetMin = new Vector2(0, 0); content.offsetMax = new Vector2(0, contentYSize); content.localPosition = new Vector2(0, -contentYSize / 2); for (int i = nowAmount; i < totalAmount; i++) { Transform newUnit = Instantiate(unit); newUnit.SetParent(content); ProductUnit unitInfo = newUnit.GetComponent <ProductUnit>(); units.Add(unitInfo); RectTransform rectTransform = newUnit.GetComponent <RectTransform>(); rectTransform.offsetMin = Vector2.zero; rectTransform.offsetMax = new Vector2(0, ySize); rectTransform.localPosition = new Vector2(0, contentYSize / 2 + -ySize * i - ySize / 2); } nowAmount += amount; return(units); }
public void Creating_WithInvalidUnit_ThrowsException(string unit) { var sut = new ProductUnitBuilder().WithValue(unit); Assert.IsFalse(ProductUnit.IsValid(unit)); Assert.Throws <ArgumentOutOfRangeException>(() => sut.Build()); }
public JsonResult CreateProductUnit(UnitViewModel model) { try { model.Id = Guid.NewGuid().ToString(); var unitId = Guid.NewGuid(); var unit = new Unit { Id = unitId, UnitName = model.UnitName }; var productUnit = new ProductUnit { Id = Guid.NewGuid(), ProductId = new Guid(model.ProductId), UnitId = unitId }; GenericFactory.Business.CreateProductUnit(unit, productUnit); return(Json("")); } catch (Exception ex) { var msg = ex.Message; } return(Json(null)); }
private string FormatProductUnit(ProductUnit unitType) { switch (unitType) { case ProductUnit.Kilogram: return("кг"); case ProductUnit.Meter: return("м"); case ProductUnit.Liter: return("л"); case ProductUnit.SquareMeter: return("м²"); case ProductUnit.CubicMeter: return("м³"); case ProductUnit.Tonne: return("т"); case ProductUnit.RunningMeter: return("пог. м"); case ProductUnit.Piece: return("шт"); default: throw new ArgumentOutOfRangeException(nameof(unitType), unitType.ToString()); } }
public static void Seed() { using var _ctx = new Context(); _ctx.Database.EnsureDeleted(); _ctx.Database.EnsureCreated(); var reg1 = new Region("Covilhã"); var comp1 = new Company("pingo ácido", 123456789); var est1 = new Establishment("Avenida da liberdade, numero 1029, Lisboa", "09:00", "20:00", "Domingo", reg1.Id, comp1.Id); var cat1 = new Category("Non-Alcoholic Beverages"); var bra1 = new Brand("Dona Edite"); var prof1 = new Profile(123456789, "Paulo", "Macabres", 919191919, DateTime.UtcNow); var sb1 = new ShoppingBasket(prof1.Id); var mod1 = new ProductModel("Vinho Tinto da Barraca do Tejo", "506-1237-424", "oklmwelkmcwekmowmcklm", 3.99, 0.75, Measure.Kg, bra1.Id, cat1.Id); var stoQ1 = new StoreQueue(42, est1.Id); var resQ1 = new ReservedQueue(est1.Id, prof1.Id); var unit1 = new ProductUnit("lolada69420", false, mod1.Id, est1.Id, sb1.Id); _ctx.Regions.AddRange(reg1); _ctx.Companies.AddRange(comp1); _ctx.Establishments.AddRange(est1); _ctx.Categories.AddRange(cat1); _ctx.Brands.AddRange(bra1); _ctx.Profiles.AddRange(prof1); _ctx.ShoppingBaskets.AddRange(sb1); _ctx.ProductModels.AddRange(mod1); _ctx.StoreQueues.AddRange(stoQ1); _ctx.ReservedQueues.AddRange(resQ1); _ctx.ProductUnits.AddRange(unit1); _ctx.SaveChanges(); }
/// <summary> /// 保存单位 /// </summary> /// <param name="unit"></param> /// <returns></returns> public JsonResult SaveUnit(string unit) { JavaScriptSerializer serializer = new JavaScriptSerializer(); ProductUnit model = serializer.Deserialize <ProductUnit>(unit); string UnitID = ""; if (string.IsNullOrEmpty(model.UnitID)) { UnitID = new ProductsBusiness().AddUnit(model.UnitName, model.Description, CurrentUser.UserID, CurrentUser.ClientID); } else { bool bl = new ProductsBusiness().UpdateUnit(model.UnitID, model.UnitName, model.Description, CurrentUser.UserID); if (bl) { UnitID = model.UnitID; } } JsonDictionary.Add("ID", UnitID); return(new JsonResult { Data = JsonDictionary, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Email,Phone,Address,Status")] ProductUnit item) { if (id != item.Id) { return(NotFound()); } if (ModelState.IsValid) { try { item.UpdatedAt = DateTime.Now; _context.Update(item); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductUnitExists(item.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(item)); }
public void CreatedProductUnit_CheckProperties() { var product = new ProductUnit("Book", 10); Assert.NotEqual(Guid.Empty, product.Id); Assert.Equal("Book", product.Name); Assert.Equal(10, product.UnitPrice); }
public SalesInvoiceLine(ProductName name, int amount, ProductUnit unit, decimal unitNetPrice, FinnishVatPercentage vatPercentage) { Name = name; Amount = amount; Unit = unit; UnitNetPrice = unitNetPrice; VatPercentage = vatPercentage; }
private void SaveProductUnit() { Models.ProductUnit productUnit = new ProductUnit(); productUnit.Unit = PUUnit; productUnit.UnitFullName = PUName; _unitOfWork.ProductUnitRepository.Insert(productUnit); _unitOfWork.CommitAsync(); }
public ActionResult UpdateUnit(ProductUnit model) { var unit = db.ProductUnit.SingleOrDefault(p => p.UnitID == model.UnitID); unit.UnitSize = model.UnitSize; db.SaveChanges(); return(Json("Update Successfully", JsonRequestBehavior.AllowGet)); }
public void Given_Order_WhenAddItemByUnit_ThenReturns_OrderItemsQuantity() { var product = new ProductUnit("Book", 10.0m); _order.AddItem(product, 5); Assert.Single(_order.OrderItems); }
public void Given_OrderCreated_WhenAddItem_ThenCheck_OrderItemsAreNotEmpty() { var product = new ProductUnit("Book", 10.0m); _order.AddItem(product, 10.0m); Assert.NotEmpty(_order.OrderItems); }
public async Task <int> Add(ProductUnit _model) { _model.CreatedUser = scopeContext.UserCode; _model.CreatedDate = DateTime.Now; context.Add(_model); await context.SaveChangesAsync(); return(_model.Id); }
private void GetProductUnit() { ProductUnit = _unitOfWork.ProductUnitRepository.GetAllAsync(); if (!ProductUnit.IsCompleted) { ProductUnit.Wait(); } RingVisibility = false; }
private static bool ContainsUnit(IReadOnlyList <OcrResult.Word> words) { if (words.Count <= UnitIndex) { return(false); } return(ProductUnit.IsValid(words[UnitIndex].Text)); }
public ProductUnit ToModel(ProductUnit model) { model.SerialNumber = SerialNumber; model.IsReserved = IsReserved; model.ProductModelId = ProductModelId; model.EstablishmentId = EstablishmentId; model.ShoppingBasketId = ShoppingBasketId; return(model); }
public async Task <bool> Modify(ProductUnit _model) { _model.UpdatedUser = scopeContext.UserCode; _model.UpdatedDate = DateTime.Now; context.Update(_model); await context.SaveChangesAsync(); return(true); }
public ActionResult Edit(ProductUnit productunit) { if (ModelState.IsValid) { db.Entry(productunit).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(productunit); }
public ActionResult Create(ProductUnit productunit) { if (ModelState.IsValid) { db.ProductUnits.Add(productunit); db.SaveChanges(); return RedirectToAction("Index"); } return View(productunit); }
private void cmdSave_Click(object sender, EventArgs e) { if (txtProductUnit.Text.Length > 0) { ProductUnit productunit = new ProductUnit(); if (ProductUnitID.Length > 0) { productunit.ProductUnitID = int.Parse(ProductUnitID); } productunit.Name = txtProductUnit.Text.ToString(); productunit.Description = mmeDescription.Text.ToString(); productunit.IsActive = Convert.ToBoolean(chkIsActive.EditValue); ProductService.SaveProductUnit(productunit); grdProductUnit.DataSource = ProductService.GetAllProductUnit(); } else { MessageBox.Show("Please, fill the product unit up!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProductUnit.Focus(); } }
public void SaveProductUnit(ProductUnit productunit) { ProductUnit existingData = GetProductUnitByID(productunit.ProductUnitID); if (existingData == null) _context.ProductUnits.AddObject(productunit); else { existingData.Name = productunit.Name; existingData.Description = productunit.Description; existingData.IsActive = productunit.IsActive; existingData.ProductUnitID = productunit.ProductUnitID; if (!_context.IsAttached(existingData)) _context.ProductUnits.Attach(existingData); } _context.SaveChanges(); }