public ItemHeader(Item item) { this.Id = item.Id.ToString(); this.Name = item.Name; this.Available = item.Available; this.PicturePath = item.PicturePath; this.OriginalPrice = item.OriginalPrice; this.DiscountedPrice = item.DiscountedPrice; this.AverageRating = item.Ratings.Any() ? Convert.ToInt32(item.Ratings.Average(x => x.Value)) : 0; this.Manufacturer = item.Manufacturer; this.ShortDescription = item.ShortDescription; this.Description = item.Description; this.GamingFlag = item.GamingFlag; this.IsUsed = item.IsUsed; this.HasRGB = item.HasRGB; this.Category = EnumExtensionMethods.GetDescription(item.Category); if (item is Motherboard) { this.CpuSocket = (item as Motherboard).Socket; } if (item is Cpu) { this.CpuSocket = (item as Cpu).Socket; } }
public FinalizeOrderDTO GetDataForFinalizeOrder(Guid userId) { var user = this.context.Users.Include(x => x.CartItems).SingleOrDefault(x => x.Id == userId); var items = new List <Item>(); user.CartItems.ForEach(x => { items.Add(this.context.Items.SingleOrDefault(i => i.Id == x.ItemId)); }); int priceSum = 0; items.ForEach(x => { priceSum += (x.DiscountedPrice != null ? x.DiscountedPrice.Value : x.OriginalPrice) * user.CartItems.Single(y => y.ItemId == x.Id).Quantity; }); var dto = new FinalizeOrderDTO() { BillingData = new UserBillingDataDTO(user), PaymentMethods = new List <string>() { EnumExtensionMethods.GetDescription(PaymentMethod.AdvancePayment), EnumExtensionMethods.GetDescription(PaymentMethod.OnlineCreditCard), EnumExtensionMethods.GetDescription(PaymentMethod.WhenDelivered) }, PriceSum = priceSum }; return(dto); }
public SpecificProperties(Item item) { if (item is Case) { Case pcCase = item as Case; this.BuiltInFanNumber = pcCase.BuiltInFanNumber; this.SupportedMotherboard = EnumExtensionMethods.GetDescription(pcCase.SupportedMotherboard); this.Height = pcCase.Height; this.Width = pcCase.Width; this.Depth = pcCase.Depth; this.HDDNumber = pcCase.HDDNumber; } if (item is Cpu) { Cpu cpu = item as Cpu; this.ProcessorFamily = cpu.ProcessorFamily; this.Technology = cpu.Technology; this.CoreNumber = cpu.CoreNumber; this.ThreadNumber = cpu.ThreadNumber; this.Socket = Socket; this.BaseClock = cpu.BaseClock; this.TDP = cpu.TDP; } if (item is GraphicsCard) { GraphicsCard gpu = item as GraphicsCard; this.BuiltInMemory = gpu.BuiltInMemory; this.MemoryClock = gpu.MemoryClock; this.BandWidth = gpu.BandWidth; this.CoolerType = gpu.CoolerType; this.MemoryType = MemoryType; this.PowerSupplyConnection = gpu.PowerSupplyConnection; this.BaseClock = gpu.BaseClock; this.TDP = gpu.TDP; } if (item is HardDrive) { HardDrive drive = item as HardDrive; this.Size = drive.Size; this.ReadSpeed = drive.ReadSpeed; this.WriteSpeed = drive.WriteSpeed; this.Weight = drive.Weight; this.DriveSocket = drive.Socket; } if (item is Memory) { Memory mem = item as Memory; this.BaseClock = mem.BaseClock; this.Capacity = mem.Capacity; this.MemoryTypeForMmoryCard = mem.MemoryType; this.Timing = mem.Timing; this.Kit = mem.Kit; } if (item is Motherboard) { Motherboard board = item as Motherboard; this.Type = board.Type; this.Chipset = board.Chipset; this.CpuSocketForMotherboard = board.Socket; this.SupportedMemoryType = board.SupportedMemoryType; this.SupportedMemorySpeed = board.SupportedMemorySpeed; this.MemorySocketNumber = board.MemorySocketNumber; } if (item is PowerSupply) { PowerSupply psu = item as PowerSupply; this.ATXConnector = psu.ATXConnector; this.MolexConnector = psu.MolexConnector; this.SixPinConnector = psu.SixPinConnector; this.SixPlusTwoConnector = psu.SixPlusTwoConnector; this.Efficiency = psu.Efficiency; this.IsModular = psu.IsModular; } if (item is CompletPC) { CompletPC pc = item as CompletPC; this.Case = pc.Case; this.Motherboard = pc.Motherboard; this.Cpu = pc.Cpu; this.Gpu = pc.Gpu; this.Memories = pc.Memories; this.Drives = pc.Drives; this.PowerSupply = pc.PowerSupply; } }
public PagedResult <ItemHeader> GetAllItems(ItemSpecification specification = null) { if (specification == null) { specification = new ItemSpecification(); } if (specification.PageSize < 0) { specification.PageSize = null; } if (specification.PageNumber < 0) { specification.PageNumber = null; } IQueryable <Item> query = this.context.Items .Include(x => x.Ratings); if (!string.IsNullOrWhiteSpace(specification.ComplexFilter)) { query = query.Where(x => x.Name.Contains(specification.ComplexFilter) || x.Manufacturer.Contains(specification.ComplexFilter) || x.ShortDescription.Contains(specification.ComplexFilter)); } if (!string.IsNullOrWhiteSpace(specification.Name)) { query = query.Where(x => x.Name.Contains(specification.Name)); } if (specification.SelectedCategories.Any()) { var selectedCategoriesEnum = new List <Category>(); specification.SelectedCategories.ForEach(x => { selectedCategoriesEnum.Add(EnumExtensionMethods.GetValueFromDescription <Category>(x)); }); query = query.Where(x => selectedCategoriesEnum.Contains(x.Category)); } if (specification.SelectedManufacturers.Any()) { query = query.Where(x => specification.SelectedManufacturers.Contains(x.Manufacturer)); } if (specification.HasRGB.HasValue) { query = query.Where(x => x.HasRGB == specification.HasRGB); } if (specification.IsNewArrival.HasValue) { query = query.Where(x => x.DateSinceInStore > DateTime.Now.AddDays(-30)); } if (specification.IsDiscounted.HasValue) { query = query.Where(x => x.DiscountedPrice != null && x.DiscountedPrice < x.OriginalPrice); } if (specification.IsGaming.HasValue) { query = query.Where(x => x.GamingFlag == specification.IsGaming); } if (specification.IsUsed.HasValue) { query = query.Where(x => x.IsUsed == specification.IsUsed); } if (specification.MinPrice != null) { query = query.Where(x => (x.DiscountedPrice ?? x.OriginalPrice) >= specification.MinPrice); } if (specification.MaxPrice != null) { query = query.Where(x => (x.DiscountedPrice ?? x.OriginalPrice) <= specification.MaxPrice); } if (specification.MinRating != null) { query = query.Where(x => (x.Ratings.Any() ? Convert.ToInt32(x.Ratings.Average(y => y.Value)) : 0) >= specification.MinRating); } if (specification.MaxRating != null) { query = query.Where(x => (x.Ratings.Any() ? Convert.ToInt32(x.Ratings.Average(y => y.Value)) : 0) <= specification.MaxRating); } //order switch (specification.Order) { case ItemSpecification.ItemOrder.PriceAscending: query = query.OrderBy(x => x.DiscountedPrice ?? x.OriginalPrice); break; case ItemSpecification.ItemOrder.PriceDescending: query = query.OrderByDescending(x => x.DiscountedPrice ?? x.OriginalPrice); break; case ItemSpecification.ItemOrder.RatingAscending: query = query.OrderBy(x => (x.Ratings.Any() ? Convert.ToInt32(x.Ratings.Average(y => y.Value)) : 0)); break; case ItemSpecification.ItemOrder.RatingDescending: query = query.OrderByDescending(x => (x.Ratings.Any() ? Convert.ToInt32(x.Ratings.Average(y => y.Value)) : 0)); break; } int?allResultsCount = null; if ((specification.PageSize ?? 0) != 0) { specification.PageNumber ??= 0; allResultsCount = query.Count(); query = query .Skip(specification.PageNumber.Value * specification.PageSize.Value) .Take(specification.PageSize.Value); } int totalMaxPrice, totalMinPrice; var maxDiscounted = context.Items.Max(x => x.DiscountedPrice); var maxOriginal = context.Items.Max(x => x.OriginalPrice); var minDiscounted = context.Items.Min(x => x.DiscountedPrice); var minOriginal = context.Items.Min(x => x.OriginalPrice); if (maxDiscounted != null) { totalMaxPrice = maxOriginal > maxDiscounted ? maxOriginal : maxDiscounted.Value; totalMinPrice = maxOriginal > maxDiscounted ? minOriginal : minDiscounted.Value; } else { totalMaxPrice = maxOriginal; totalMinPrice = minOriginal; } return(new PagedResult <ItemHeader> { AllResultsCount = allResultsCount, Results = query.ToList().Select(ItemHeaderSelectorFunc.Value), Categories = context.Items.Select(x => EnumExtensionMethods.GetDescription(x.Category)).Distinct().ToList(), Manufacturers = context.Items.Select(x => x.Manufacturer).Distinct().ToList(), TotalMaxPrice = totalMaxPrice, TotalMinPrice = totalMinPrice, PageNumber = specification.PageNumber, PageSize = specification.PageSize, Specification = specification, }); }