public async Task <IHttpActionResult> PutPriceProduct(int id, PriceProduct priceProduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != priceProduct.Id) { return(BadRequest()); } db.Entry(priceProduct).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PriceProductExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool Equals(Product other) { if (other == null) { return(false); } else { if (!TypeProduct.Equals(other.TypeProduct)) { return(false); } if (!NameProduct.Equals(other.NameProduct)) { return(false); } if (!PriceProduct.Equals(other.PriceProduct)) { return(false); } if (!QuantityProduct.Equals(other.QuantityProduct)) { return(false); } } return(true); }
public PriceProductDetail(PriceProduct priceProduct) { InitializeComponent(); var productViewModel = new PriceProductDetailViewModel(Navigation); productViewModel.PriceProduct = priceProduct; BindingContext = productViewModel; }
public AbstractEntity Parse(Gtin.Gtin gtin) { AbstractEntity entity = null; string code = gtin.Code; if (gtin is Gtin13) { int mode = int.Parse(code[0].ToString()); switch (mode) { case 2: // Weight or price int mode2 = int.Parse(code[1].ToString()); if (mode2 >= 0 && mode2 <= 2) { int divider = price_dividers[mode2]; float price = int.Parse(code.Substring(8, 4)); entity = new PriceProduct(code.Substring(2, 6), (divider == 0 ? price : price / divider)); } else if (mode2 >= 3 && mode2 <= 5) { int divider = weight_dividers[mode2]; float weight = int.Parse(code.Substring(8, 4)); entity = new WeightProduct(code.Substring(2, 6), weight / divider); } break; case 7: if (code.Substring(0, 4) == "7388") { // Publication entity = new Publication(code.Substring(4, 4), float.Parse(code.Substring(8, 4)) / 10); } break; case 9: // Coupon entity = new Coupon(code.Substring(2, 6), float.Parse(code.Substring(8, 4)) / 10); break; default: entity = new Product(code.Substring(6, 6), code.Substring(0, 6)); break; } } else { entity = new Product(code.Substring(6, 1), code.Substring(0, 6)); } return(entity); }
public override string ToString() { return(product.NameProduct + ", $" + PriceProduct.ToString("F2", CultureInfo.InvariantCulture) + ", Quantity: " + QtdProduct + ", Subtotal: $" + SubTotal().ToString("F2", CultureInfo.InvariantCulture)); }
public async Task <IHttpActionResult> GetPriceProduct(int id) { PriceProduct priceProduct = await db.PriceProduct.FindAsync(id); if (priceProduct == null) { return(NotFound()); } return(Ok(priceProduct)); }
public async Task <IHttpActionResult> PostPriceProduct(PriceProduct priceProduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.PriceProduct.Add(priceProduct); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = priceProduct.Id }, priceProduct)); }
public async Task <IHttpActionResult> DeletePriceProduct(int id) { PriceProduct priceProduct = await db.PriceProduct.FindAsync(id); if (priceProduct == null) { return(NotFound()); } db.PriceProduct.Remove(priceProduct); await db.SaveChangesAsync(); return(Ok(priceProduct)); }
public void Post([FromBody] Product value) { _db.Entry(value.Business).State = EntityState.Unchanged; _db.Entry(value.Category).State = EntityState.Unchanged; _db.Products.Add(value); if (value.Price > 0) { PriceProduct pp = new PriceProduct(); pp.Price = value.Price; pp.Product = value; pp.RegisteredDate = DateTime.Now; _db.PriceProducts.Add(pp); } _db.SaveChanges(); }
public void Put(int id, [FromBody] PriceProduct value) { _db.Entry(value).State = EntityState.Modified; _db.SaveChanges(); }
public void Post([FromBody] PriceProduct value) { _db.Entry(value.Product).State = EntityState.Modified; _db.PriceProducts.Add(value); _db.SaveChanges(); }
static void Generate() { try { Console.WriteLine("GS1 GTIN generator"); Console.WriteLine("==================\n"); Console.WriteLine("Select entity type:"); Console.WriteLine(" 0 - Weight"); Console.WriteLine(" 1 - Price"); Console.WriteLine(" 2 - Publication"); Console.WriteLine(" 3 - Coupon"); int choice = int.Parse(Console.ReadLine()); string sku = ""; string id = ""; float price = 0; float weight = 0; string code = ""; AbstractEntity product; if (choice < 3) { Console.WriteLine("Enter SKU: "); sku = Console.ReadLine(); } else { Console.WriteLine("Enter ID: "); id = Console.ReadLine(); } if (choice > 0) { Console.WriteLine("Enter Price: "); price = float.Parse(Console.ReadLine()); } else { Console.WriteLine("Enter Weight: "); weight = float.Parse(Console.ReadLine()); } switch (choice) { case 0: product = new WeightProduct(sku, weight); break; case 1: product = new PriceProduct(sku, price); break; case 2: product = new Publication(sku, price); break; case 3: product = new Coupon(id, price); break; default: product = null; break; } code = GtinFactory.Get("Sweden", product).ToString(); Console.WriteLine("GTIN code: " + code); Console.ReadLine(); } catch (FormatException) { Console.WriteLine("Fel in-värde"); } }
static void Parse() { try { Console.WriteLine("GS1 GTIN parser"); Console.WriteLine("===============\n"); Console.WriteLine("Enter GTIN (8 or 13 chars):"); string code = Console.ReadLine(); Gtin.Gtin gtin; if (code.Length == 8) { gtin = new Gtin8(code); } else if (code.Length == 13) { gtin = new Gtin13(code); } else { throw new ArgumentException("GTIN must be 8 or 13 characters"); } if (!gtin.IsValid()) { throw new ArgumentException("GTIN checksum not valid"); } AbstractEntity entity = EntityFactory.Get("Sweden", gtin); if (entity is Product) { Product product = (Product)entity; Console.WriteLine("Company Prefix: " + product.CompanyPrefix); Console.WriteLine("SKU: " + product.Sku); } else if (entity is WeightProduct) { WeightProduct product = (WeightProduct)entity; Console.WriteLine("SKU: " + product.Sku); Console.WriteLine("Weight: " + product.Weight); } else if (entity is PriceProduct) { PriceProduct product = (PriceProduct)entity; Console.WriteLine("SKU: " + product.Sku); Console.WriteLine("Price: " + product.Price); } else if (entity is Coupon) { Coupon coupon = (Coupon)entity; Console.WriteLine("ID (Coupon): " + coupon.Id); Console.WriteLine("Discount: " + coupon.Value); } else if (entity is Publication) { Publication publication = (Publication)entity; Console.WriteLine("SKU (Publication): " + publication.Sku); Console.WriteLine("Price: " + publication.Price); } Console.ReadLine(); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } catch (FormatException) { Console.WriteLine("Fel in-värde"); } }
public Gtin.Gtin Generate(AbstractEntity entity) { Gtin.Gtin gtin = null; IFormatProvider numberFormat = CultureInfo.InvariantCulture; if (entity is Product) { Product product = (Product)entity; try { gtin = new Gtin8(); gtin.SetPart(6, product.CompanyPrefix); gtin.SetPart(1, product.Sku); } catch (ArgumentException) { gtin = new Gtin13(); gtin.SetPart(9, product.CompanyPrefix); gtin.SetPart(3, product.Sku); } } else if (entity is WeightProduct) { gtin = new Gtin13(); WeightProduct product = (WeightProduct)entity; decimal weight = (decimal)product.Weight; int decimals = GetDecimalsCount(weight); int modulator; string weight_str = SubstringMax(weight.ToString(numberFormat).Replace(".", ""), 0, 4); if (decimals == 0) { decimals = 3; weight_str += "000"; } else { decimals = Math.Max(1, Math.Min(3, decimals)); } modulator = weight_modulators[decimals]; gtin.SetPart(2, "2" + modulator); gtin.SetPart(6, product.Sku); gtin.SetPart(4, weight_str); } else if (entity is PriceProduct) { gtin = new Gtin13(); PriceProduct product = (PriceProduct)entity; decimal price = (decimal)product.Price; int decimals = GetDecimalsCount(price); int modulator; string price_str = SubstringMax(price.ToString(numberFormat).Replace(".", ""), 0, 4); decimals = Math.Max(0, Math.Min(2, decimals)); modulator = price_modulators[decimals]; gtin.SetPart(2, "2" + modulator); gtin.SetPart(6, product.Sku); gtin.SetPart(4, price_str); } else if (entity is Publication) { gtin = new Gtin13(); Publication product = (Publication)entity; decimal price = (decimal)product.Price; int decimals = GetDecimalsCount(price); string price_str = price.ToString(numberFormat).Replace(".", ""); if (decimals == 0) { price_str = SubstringMax(price_str, 0, 3) + "0"; } else { price_str = SubstringMax(price_str, 0, 4); } gtin.SetPart(4, "7388"); gtin.SetPart(4, product.Sku); gtin.SetPart(4, price_str); } else if (entity is Coupon) { gtin = new Gtin13(); Coupon coupon = (Coupon)entity; decimal value = (decimal)coupon.Value; int decimals = GetDecimalsCount(value); string value_str = value.ToString(numberFormat).Replace(".", ""); if (decimals == 0) { value_str = SubstringMax(value_str, 0, 3) + "0"; } else { value_str = SubstringMax(value_str, 0, 4); } gtin.SetPart(2, "99"); gtin.SetPart(6, coupon.Id); gtin.SetPart(4, value_str); } return(gtin); }