public void StoreEnumInheritedTypesSerializesCorrectlyForSpecialProduct() { using (var trn = Store.BeginTransaction()) { var originalSpecial = new SpecialProduct() { Name = "Unicorn Dust", BonusMaterial = "Directors Commentary", Id = "UD-01", Price = 11.1m, }; var originalDud = new DodgyProduct() { Id = "DO-01", Name = "Something", Price = 12.3m, Tax = 15m }; trn.Insert <SpecialProduct>(originalSpecial); trn.Insert <DodgyProduct>(originalDud); var allProducts = trn.TableQuery <ProductToTestSerialization>().ToList(); var special = allProducts.Single(p => p.Id == "UD-01"); special.Type.Should().Be("Special", "Type isn't serializing into column correctly"); special.JSON.Should().Be("{\"Type\":1,\"Price\":11.1}"); } }
public void StoreEnumInheritedTypesSerializesCorrectlyForSpecialProduct() { using (var trn = Store.BeginTransaction()) { var originalSpecial = new SpecialProduct { Name = "Unicorn Dust", BonusMaterial = "Directors Commentary", Id = "UD-01", Price = 11.1m, }; var originalDud = new DodgyProduct { Id = "DO-01", Name = "Something", Price = 12.3m, Tax = 15m }; trn.Insert(originalSpecial); trn.Insert(originalDud); var allProducts = trn.Stream <(string Id, string Type, string JSON)>("select Id, Type, [JSON] from TestSchema.Product").ToList(); var special = allProducts.Single(p => p.Id == "UD-01"); special.Type.Should().Be("Special", "Type isn't serializing into column correctly"); special.JSON.Should().Be("{\"BonusMaterial\":\"Directors Commentary\",\"Price\":11.1}"); } }
public void StoreAndLoadInheritedTypes() { using (var trn = Store.BeginTransaction()) { var originalSpecial = new SpecialProduct() { Name = "Unicorn Dust", BonusMaterial = "Directors Commentary", Id = "UD-01", Price = 11.1m, }; var originalDud = new DodgyProduct() { Id = "DO-01", Name = "Something", Price = 12.3m, Tax = 15m }; trn.Insert <SpecialProduct>(originalSpecial); trn.Insert <DodgyProduct>(originalDud); var allProducts = trn.TableQuery <Product>().ToList(); Assert.True(allProducts.Exists(p => p is SpecialProduct sp && sp.BonusMaterial == originalSpecial.BonusMaterial)); Assert.True(allProducts.Exists(p => p is DodgyProduct dp && dp.Tax == originalDud.Tax)); var onlySpecial = trn.TableQuery <SpecialProduct>().ToList(); Assert.Equal(1, onlySpecial.Count); Assert.Equal(originalSpecial.BonusMaterial, onlySpecial[0].BonusMaterial); } }
public IActionResult CreateNotAllowed([FromBody] SpecialProduct specialProduct) { if (specialProduct == null) { return(BadRequest()); } string userJWTId = User.FindFirst("id")?.Value; Customer customer = db.GetCustomer(userJWTId); if (customer != null) { specialProduct.CustomerId = customer.Id; } specialProduct.Allowance = 0; SpecialProductKey sk = new SpecialProductKey(); sk.ProductId = specialProduct.ProductId; sk.CustomerId = specialProduct.CustomerId; SpecialProduct testSpecialProduct = db.GetEntity(sk); if (testSpecialProduct == null) { db.Create(specialProduct); } db.Save(); return(Ok(specialProduct)); }
public IActionResult Change([FromBody] SpecialProduct specialProduct) { if (specialProduct == null) { return(BadRequest()); } db.Update(specialProduct); db.Save(); return(Ok(specialProduct)); }
public IActionResult Get([FromQuery] SpecialProductKey id) { SpecialProduct specialProduct = db.GetEntity(id); if (specialProduct == null) { return(NotFound()); } return(new ObjectResult(specialProduct)); }
public IActionResult Update([FromBody] Customer customer) { if (customer == null) { return(BadRequest()); } string userJWTId = User.FindFirst("id")?.Value; Customer appropriateCustomer = db.GetCustomer(userJWTId); if (appropriateCustomer != null) { customer.Id = appropriateCustomer.Id; } if (customer.FoodStyleId != null) { FoodStyle foodStyle = fr.GetWholeEntity(customer.FoodStyleId); customer.CaloricGoal = foodStyle.CaloricValue; List <FoodStyleProduct> foodStyleProducts = foodStyle.FoodStyleProduct.ToList(); List <SpecialProduct> specialProducts = customer.SpecialProduct.ToList(); List <int> specialProductsIds = new List <int>(); for (int i = 0; i < specialProducts.Count(); i++) { specialProductsIds.Add(specialProducts[i].ProductId); } for (int i = 0; i < foodStyleProducts.Count(); i++) { SpecialProduct newSpecialProduct = new SpecialProduct(); newSpecialProduct.CustomerId = customer.Id; newSpecialProduct.ProductId = foodStyleProducts[i].ProductId; newSpecialProduct.Allowance = 1; if (specialProductsIds.Contains(foodStyleProducts[i].ProductId)) { sr.Update(newSpecialProduct); } else { sr.Create(newSpecialProduct); } sr.Save(); } } db.Update(customer); db.Save(); return(Ok(customer)); }
public SpecialProduct GetSpecialProduct() { SpecialProduct special = new SpecialProduct(); c.BaseAddress = new Uri(url); c.DefaultRequestHeaders.Accept.Clear(); c.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json") ); HttpResponseMessage response = c.GetAsync("api/product/specialproduct").Result; special = response.Content.ReadAsAsync <SpecialProduct>().Result; return(special); }
public IActionResult Delete([FromQuery] SpecialProductKey id) { string userJWTId = User.FindFirst("id")?.Value; Customer customer = db.GetCustomer(userJWTId); if (customer != null) { id.CustomerId = customer.Id; } SpecialProduct specialProduct = db.GetEntity(id); if (specialProduct == null) { return(NotFound()); } db.Delete(id); db.Save(); return(Ok(specialProduct)); }
public void StoreAndLoadEnumInheritedTypes() { using (var trn = Store.BeginTransaction()) { var originalNormal = new Product { Name = "Norm", Id = "NL-01", Price = 15.5m }; var originalSpecial = new SpecialProduct { Name = "Unicorn Dust", BonusMaterial = "Directors Commentary", Id = "UD-01", Price = 11.1m }; var originalDud = new DodgyProduct { Id = "DO-01", Name = "Something", Price = 12.3m, Tax = 15m }; trn.Insert(originalNormal); trn.Insert <SpecialProduct>(originalSpecial); trn.Insert <DodgyProduct>(originalDud); var allProducts = trn.TableQuery <Product>().ToList(); Assert.True(allProducts.Exists(p => p is SpecialProduct sp && sp.BonusMaterial == originalSpecial.BonusMaterial), "Special product didn't load correctly"); Assert.True(allProducts.Exists(p => p is DodgyProduct dp && dp.Tax == originalDud.Tax), "Dodgy product didn't load correctly"); var onlySpecial = trn.TableQuery <SpecialProduct>().ToList(); onlySpecial.Count.Should().Be(1); onlySpecial[0].BonusMaterial.Should().Be(originalSpecial.BonusMaterial); } }
public SpecialProduct GetSpecialProduct() { SpecialProduct specialProductViewModel = new SpecialProduct(); var specialproduct = db.SANPHAMs.Where(sp => sp.DAXOA.Value.Equals(false) && sp.SANPHAMBANCHAY.Value.Equals(true)).ToList().First(); int makhuyenmai = specialproduct.MAKHUYENMAI.Value; if (makhuyenmai != 0) { var _mkm = db.KHUYENMAIs.Where(km => km.DAXOA.Value.Equals(false) && km.MA.Equals(makhuyenmai)).SingleOrDefault(); specialProductViewModel.promotion = (double)(specialproduct.DONGIABAN * (100 - _mkm.NOIDUNG.Value)) / 100; } else { specialProductViewModel.promotion = 0; } Mapper.CreateMap <SANPHAM, SANPHAMModel>(); specialProductViewModel.specialproduct = Mapper.Map <SANPHAM, SANPHAMModel>(specialproduct); return(specialProductViewModel); }
public IActionResult ChangeFoodStyle(int customerId, int foodStyleId) { Customer customer = db.GetWholeEntity(customerId); FoodStyle foodStyle = fr.GetWholeEntity(foodStyleId); customer.CaloricGoal = foodStyle.CaloricValue; customer.FoodStyleId = foodStyleId; List <FoodStyleProduct> foodStyleProducts = foodStyle.FoodStyleProduct.ToList(); List <SpecialProduct> specialProducts = customer.SpecialProduct.ToList(); List <int> specialProductsIds = new List <int>(); for (int i = 0; i < specialProducts.Count(); i++) { specialProductsIds.Add(specialProducts[i].ProductId); } for (int i = 0; i < foodStyleProducts.Count(); i++) { SpecialProduct newSpecialProduct = new SpecialProduct(); newSpecialProduct.CustomerId = customer.Id; newSpecialProduct.ProductId = foodStyleProducts[i].ProductId; newSpecialProduct.Allowance = 1; if (specialProductsIds.Contains(foodStyleProducts[i].ProductId)) { sr.Update(newSpecialProduct); } else { sr.Create(newSpecialProduct); } sr.Save(); } db.Update(customer); db.Save(); fo.Save(); return(new ObjectResult("Succesful operation!")); }
public ConcreteCreator() { product = new SpecialProduct(); //Console.WriteLine(product.GetType().Name); }