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));
            }
        }