Example #1
0
        // GET: PCCase


        public ActionResult SetHardware(int id, int assemblyId)
        {
            var computerAssembly = _computerAssemblyService.GetComputerAssembly(assemblyId);

            if (computerAssembly == null)
            {
                return(NotFound());
            }
            var userId = _userService.GetApplicationUserManager().GetUserId(this.User);

            if (computerAssembly.OwnerId != userId)
            {
                return(Forbid());
            }
            var result = _computerAssemblyService.SetPCCase(id, assemblyId);

            return(Json(result));
        }
        public IActionResult EvaluateResult(int id, int assemblyId)
        {
            var computerAssembly = _computerAssemblyService.GetComputerAssembly(assemblyId);

            if (computerAssembly == null)
            {
                return(NotFound());
            }
            var userId = _userService.GetApplicationUserManager().GetUserId(this.User);

            if (computerAssembly.OwnerId != userId)
            {
                return(Forbid());
            }
            var software = _softwareService.GetSoftware(id);

            if (software == null)
            {
                return(NotFound());
            }

            var result = _computerAssemblyService.SoftwareSyncEvaluate(id, computerAssembly);

            if (!result.Succedeed)
            {
                return(Json(result));
            }

            var model = new SoftwareResultViewModel();

            model.ComputerAssembly = computerAssembly;
            model.Software         = new SoftwareViewModel()
            {
                Id               = software.Id,
                Name             = software.Name,
                ShortDescription = string.IsNullOrEmpty(software.Description) ? "" : CreateShortDescription(software.Description),
                Publisher        = software.Publisher.Name,
                Developer        = software.Developer.Name,
                RecomendedCPURequirmentsDisplay       = CreateCPuDisplay(software.SoftwareCPURequirements.Where(m => m.RequirementTypeId == 2).ToList()),
                RecomendedVideoCardRequirmentsDisplay = CreateVideoCardDisplay(software.SoftwareVideoCardRequirements.Where(m => m.RequirementTypeId == 2).ToList()),
                MinimiumRequiredRAMDisplay            = software.MinimiumRequiredRAM + " Гб",
                RecommendedRequiredRAMDisplay         = software.RecommendedRequiredRAM + " Гб",
                DiscVolumeDisplay                  = CreateMemoryDescription(software.DiscVolume),
                MinimumCPURequirmentsDisplay       = CreateCPuDisplay(software.SoftwareCPURequirements.Where(m => m.RequirementTypeId == 1).ToList()),
                MinimumVideoCardRequirmentsDisplay = CreateVideoCardDisplay(software.SoftwareVideoCardRequirements.Where(m => m.RequirementTypeId == 1).ToList()),
                ImagePath   = "/Images/Software/" + software.Image,
                Price       = software.Price,
                Description = software.Description
            };
            model.Result = result;

            return(PartialView(model));
        }
Example #3
0
        public IActionResult Index(int?id, string name)
        {
            if (id.HasValue)
            {
                var computerAssembly = _computerAssemblyService.GetComputerAssembly(id.Value);
                if (computerAssembly == null)
                {
                    return(NotFound());
                }

                System.Security.Claims.ClaimsPrincipal currentUser = this.User;
                var userId = _userService.GetApplicationUserManager().GetUserId(this.User);
                if (computerAssembly.OwnerId != userId)
                {
                    return(Forbid());
                }

                var model = new ComputerAssemblyViewModel();
                model.Id                  = computerAssembly.Id;
                model.Name                = computerAssembly.Name;
                model.UserId              = computerAssembly.OwnerId;
                model.CPUId               = computerAssembly.CPUId;
                model.CPUName             = computerAssembly.CPU == null ? "Пусто" : computerAssembly.CPU.Name;
                model.CPUImage            = computerAssembly.CPU == null ? "" : "/Images/CPU/" + computerAssembly.CPU.Image;
                model.MotherBoardId       = computerAssembly.MotherBoardId;
                model.MotherBoardName     = computerAssembly.MotherBoard == null ? "Пусто" : computerAssembly.MotherBoard.Name;
                model.MotherBoardImage    = computerAssembly.MotherBoard == null ? "" : "/Images/MotherBoard/" + computerAssembly.MotherBoard.Image;
                model.PCCaseId            = computerAssembly.PCCaseId;
                model.PCCaseName          = computerAssembly.PCCase == null ? "Пусто" : computerAssembly.PCCase.Name;
                model.PCCaseImage         = computerAssembly.PCCase == null ? "" : "/Images/PCCase/" + computerAssembly.PCCase.Image;
                model.PowerSupplyId       = computerAssembly.PowerSupplyId;
                model.PowerSupplyName     = computerAssembly.PowerSupply == null ? "Пусто" : computerAssembly.PowerSupply.Name;
                model.PowerSupplyImage    = computerAssembly.PowerSupply == null ? "" : "/Images/PowerSupply/" + computerAssembly.PowerSupply.Image;
                model.VideoCards          = computerAssembly.VideoCards.Select(m => new VideoCardShortModel(m.VideoCard)).ToList() ?? new List <VideoCardShortModel>();
                model.RAMs                = computerAssembly.ComputerAssemblyRAMs.Select(m => new RAMShortModel(m.RAM)).ToList() ?? new List <RAMShortModel>();
                model.SSDs                = computerAssembly.SSDs.Select(m => new SSDShortModel(m.SSD)).ToList() ?? new List <SSDShortModel>();
                model.HDDs                = computerAssembly.HDDs.Select(m => new HDDShortModel(m.HDD)).ToList() ?? new List <HDDShortModel>();
                model.RAMFreeSlot         = _computerAssemblyService.CalculateFreeRAMSlot(computerAssembly);
                model.OuterMemoryFreeSlot = _computerAssemblyService.CalculateFreeOuterMemorySlot(computerAssembly);
                model.Public              = computerAssembly.Public;
                return(View(model));
            }
            else
            {
                System.Security.Claims.ClaimsPrincipal currentUser = this.User;
                var userId             = _userService.GetApplicationUserManager().GetUserId(this.User);
                var computerAssembly   = new ComputerAssembly();
                var computerAssemblies = _computerAssemblyService.GetComputerAssemblies().Where(m => m.OwnerId == userId && m.Name == name);
                if (computerAssemblies.Any())
                {
                    return(Json(new { error = "Ви вже створили збірку з цією назвою" }));
                }
                computerAssembly.Name    = name;
                computerAssembly.OwnerId = userId;
                _computerAssemblyService.CreateComputerAssembly(computerAssembly);
                var model = new ComputerAssemblyViewModel();
                model.Id                  = computerAssembly.Id;
                model.Name                = computerAssembly.Name;
                model.UserId              = computerAssembly.OwnerId;
                model.CPUId               = computerAssembly.CPUId;
                model.CPUName             = computerAssembly.CPU == null ? "Пусто" : computerAssembly.CPU.Name;
                model.CPUImage            = computerAssembly.CPU == null ? "" : "/Images/CPU/" + computerAssembly.CPU.Image;
                model.MotherBoardId       = computerAssembly.MotherBoardId;
                model.MotherBoardName     = computerAssembly.MotherBoard == null ? "Пусто" : computerAssembly.MotherBoard.Name;
                model.MotherBoardImage    = computerAssembly.MotherBoard == null ? "" : "/Images/MotherBoard/" + computerAssembly.MotherBoard.Image;
                model.PCCaseId            = computerAssembly.PCCaseId;
                model.PCCaseName          = computerAssembly.PCCase == null ? "Пусто" : computerAssembly.PCCase.Name;
                model.PCCaseImage         = computerAssembly.PCCase == null ? "" : "/Images/PCCase/" + computerAssembly.PCCase.Image;
                model.PowerSupplyId       = computerAssembly.PowerSupplyId;
                model.PowerSupplyName     = computerAssembly.PowerSupply == null ? "Пусто" : computerAssembly.PowerSupply.Name;
                model.PowerSupplyImage    = computerAssembly.PowerSupply == null ? "" : "/Images/PowerSupply/" + computerAssembly.PowerSupply.Image;
                model.VideoCards          = new List <VideoCardShortModel>();
                model.RAMs                = new List <RAMShortModel>();
                model.SSDs                = new List <SSDShortModel>();
                model.HDDs                = new List <HDDShortModel>();
                model.RAMFreeSlot         = 1;
                model.OuterMemoryFreeSlot = 1;
                model.Public              = false;
                return(Json(model));
            }
        }