public void Test3() { var sizeVariation = new SizeVariation() { ListParams = new List <Size>() { new Size() { TypeSize = SizesEnum.Breast, Value = 90, MaxValue = 100 }, new Size() { TypeSize = SizesEnum.Waist, Value = 65, MaxValue = 70 }, new Size() { TypeSize = SizesEnum.Hips, Value = 95, MaxValue = 100 }, new Size() { TypeSize = SizesEnum.WidthOfTheShoulders, Value = 70, MaxValue = 75 } } }; var pv = new ProductVariation() { SizeVariation = new List <SizeVariation>() { sizeVariation } }; var customerSize = new UserSizes() { Breast = 92, Waist = 66, Thigh = 97, ShouldersWidth = 69, }; double expected = 7.28; pv = SizeResponseController.CalculateRating(pv, customerSize); var actual = pv.SizeVariation.FirstOrDefault().Rating; Assert.IsTrue(Math.Abs(expected - actual) < 0.1); }
public IActionResult Skirt(double?priceFrom = null, double?priceTo = null, bool?sizeForMe = null, string[] colors = null, string[] brands = null, string[] lengths = null, int?minFit = null) { var user = db.Users.Include(x => x.UserSizes).FirstOrDefault(x => x.Id == _userManager.GetUserId(HttpContext.User)); var vm = new SkirtListViewModel(); vm.AllProducts = db.ProductVariations.Include(x => x.BaseProduct).ThenInclude(x => x.Category).Include(x => x.ColorVariation).ThenInclude(x => x.ImageURLs).Include(x => x.SizeVariation).ThenInclude(x => x.ListParams) .Where(x => x.BaseProduct.Category.DressType == DressTypeEnum.DressAndSkirt).ToList(); vm.PriceFrom = priceFrom ?? vm.AllProducts.Min(x => x.Price); vm.PriceTo = priceTo ?? vm.AllProducts.Max(x => x.Price); vm.SizeForMe = sizeForMe ?? false; vm.AllColors = vm.AllProducts.Select(x => x.ColorVariation.Color).ToList(); vm.AllBrand = vm.AllProducts.Select(x => x.BaseProduct.Brand).ToList(); vm.SelectedColors = colors?.ToList() ?? new List <string>(); vm.SelectedBrand = brands?.ToList() ?? new List <string>(); vm.SelectedLength = lengths?.ToList() ?? new List <string>(); vm.MinFit = minFit ?? 1; vm.Products = vm.AllProducts; vm.Products = vm.Products.Where(x => (x.Price >= vm.PriceFrom) & (x.Price <= vm.PriceTo)).ToList(); if (vm.SelectedColors.Count != 0) { vm.Products = vm.Products.Where(x => vm.SelectedColors.Contains(x.ColorVariation.Color)).ToList(); } if (vm.SelectedBrand.Count != 0) { vm.Products = vm.Products.Where(x => vm.SelectedBrand.Contains(x.BaseProduct.Brand)).ToList(); } if (vm.SelectedLength.Count != 0) { //Todo } if (vm.SizeForMe) { for (int i = 0; i < vm.Products.Count; i++) { vm.Products[i] = SizeResponseController.CalculateRating(vm.Products[i], user.UserSizes); } vm.Products = vm.Products.Where(x => x.SizeVariation.Count(i => i.Rating >= vm.MinFit) > 0).ToList(); } return(View(vm)); }
public IActionResult ProductVariation(int productVariationID) { var pv = db.ProductVariations.Include(x => x.ColorVariation).ThenInclude(x => x.ImageURLs) .Include(x => x.BaseProduct).ThenInclude(x => x.Category).Include(x => x.SizeVariation). ThenInclude(x => x.ListParams).FirstOrDefault(x => x.ProductVariationId == productVariationID); var vm = new SkirtProducViewModel(); if (_signInManager.IsSignedIn(User)) { var userID = _userManager.GetUserId(HttpContext.User); var user = db.Users.Include(x => x.UserSizes).FirstOrDefault(x => x.Id == userID); if (pv.BaseProduct.Category.DressType == DressTypeEnum.DressAndSkirt) { //if(user.UserSizes.Breast) pv = SizeResponseController.CalculateRating(pv, user.UserSizes); } vm.User = user; var bestRating = pv.SizeVariation.Max(x => x.Rating); vm.BestSize = pv.SizeVariation.FirstOrDefault(x => Math.Abs(x.Rating - bestRating) < 0.01); } vm.Product = pv; return(View(vm)); }
public void Test2() { double expected = 5.0; Assert.AreEqual(expected, SizeResponseController.CalculateRating(80, 70, 90)); }
public void Test1() { double expected = 8.0; Assert.AreEqual(expected, SizeResponseController.CalculateRating(69, 70, 75)); }