Пример #1
0
        public IActionResult List()
        {
            var model = _computerAssemblyService.GetComputerAssemblies().Select(m => new ComputerAssemblyViewModel()
            {
                Id     = m.Id,
                Name   = m.Name,
                UserId = m.OwnerId
            });

            System.Security.Claims.ClaimsPrincipal currentUser = this.User;
            var userId = _userService.GetApplicationUserManager().GetUserId(this.User);

            return(View(model.Where(m => m.UserId == userId)));
        }
Пример #2
0
        public IActionResult AssemblyTable(AssemblySearchModel searchDetails)
        {
            var computers = _computerAssemblyService.GetComputerAssemblies().Where(m => m.Public);

            if (searchDetails != null)
            {
                if (searchDetails.MinPrice.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.CalculatePrice(m) >= searchDetails.MinPrice);
                }
                if (searchDetails.MaxPrice.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.CalculatePrice(m) <= searchDetails.MaxPrice);
                }
                if (searchDetails.MinFrequency.HasValue)
                {
                    computers = computers.Where(m => m.CPU.Frequency >= searchDetails.MinFrequency);
                }
                if (searchDetails.MaxFrequency.HasValue)
                {
                    computers = computers.Where(m => m.CPU.Frequency <= searchDetails.MaxFrequency);
                }
                if (searchDetails.MinCores.HasValue)
                {
                    computers = computers.Where(m => m.CPU.CoresNumber >= searchDetails.MinCores);
                }
                if (searchDetails.MaxCores.HasValue)
                {
                    computers = computers.Where(m => m.CPU.CoresNumber <= searchDetails.MaxCores);
                }
                if (searchDetails.MinVideoMemory.HasValue)
                {
                    computers = computers.Where(m => m.VideoCards.ElementAt(0).VideoCard.MemorySize >= searchDetails.MinVideoMemory);
                }
                if (searchDetails.MaxVideoMemory.HasValue)
                {
                    computers = computers.Where(m => m.VideoCards.ElementAt(0).VideoCard.MemorySize <= searchDetails.MaxVideoMemory);
                }
                if (searchDetails.MinRAM.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.GetTotalRAM(m) >= searchDetails.MinRAM);
                }
                if (searchDetails.MaxRAM.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.GetTotalRAM(m) >= searchDetails.MaxRAM);
                }
                if (searchDetails.MinVolume.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.GetTotalVolume(m) >= searchDetails.MinVolume);
                }
                if (searchDetails.MaxVolume.HasValue)
                {
                    computers = computers.Where(m => _computerAssemblyService.GetTotalVolume(m) <= searchDetails.MaxVolume);
                }
            }
            var model = computers.Select(m => new ComputerAssemblyViewModel()
            {
                Id        = m.Id,
                Name      = m.Name,
                UserId    = m.OwnerId,
                OwnerName = m.Owner.Name + " " + m.Owner.Surname
            });

            model = model.Where(m => string.IsNullOrEmpty(searchDetails.Name) || m.Name.Contains(searchDetails.Name) || m.OwnerName.Contains(searchDetails.Name));

            return(PartialView(model));
        }