예제 #1
0
        private void save(PCViewModel pc)
        {
            var db = new AppDbContext();

            db.PCs.Add(ToPC(pc));
            db.SaveChanges();
        }
예제 #2
0
 public ActionResult Edit(PCViewModel pc)
 {
     ViewBag.UserId = pc.UserId;
     if (ModelState.IsValid)
     {
         _serv.UpdatePC(pc);
         return(RedirectToAction("Index", new { UserId = pc.UserId }));
     }
     return(View());
 }
예제 #3
0
 public ActionResult Create(PCViewModel pc)
 {
     ViewBag.UserId = pc.UserId;
     if (ModelState.IsValid)
     {
         save(pc);
         return(RedirectToAction("Index", new { UserId = pc.UserId }));
     }
     return(View());
 }
예제 #4
0
파일: PCService.cs 프로젝트: Phylanx/CST356
        public void UpdatePC(PCViewModel pc)
        {
            var oldRecord = _rep.GetPC(pc.Id);

            oldRecord.Name            = pc.Name;
            oldRecord.GB_Memory       = pc.GB_Memory;
            oldRecord.GB_Storage      = pc.GB_Storage;
            oldRecord.MHZ_Processor   = pc.MHZ_Processor;
            oldRecord.ReadyForUpgrade = pc.ReadyForUpgrade;
            oldRecord.UserId          = pc.UserId;
        }
예제 #5
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,CustomerName,CPUId,MotherboardId,PowerSupplyId,AssemblyNeeded,SelectedMemories")] PCViewModel model)
        {
            var motherboard      = _motherboardService.Find(model.MotherboardId);
            var cpu              = _cpuService.Find(model.CPUId);
            var powerSupply      = _powerSupplyService.Find(model.PowerSupplyId);
            var selectedMemories = model.SelectedMemories.Where(item => item.IsSelected);

            if (ModelState.IsValid)
            {
                var message = ValidatePCConfiguration(motherboard, cpu, powerSupply, selectedMemories);
                if (!string.IsNullOrEmpty(message))
                {
                    ViewBag.ErrorMessage = message;
                    LoadLists();
                    return(View(model));
                }
                //begin a transaction
                _unitOfWork.BeginTransaction();
                //setup the pc
                var oldPC = _pcService.Find(model.Id);
                oldPC.CustomerName   = model.CustomerName;
                oldPC.CPUId          = model.CPUId;
                oldPC.MotherboardId  = model.MotherboardId;
                oldPC.PowerSupplyId  = model.PowerSupplyId;
                oldPC.AssemblyNeeded = model.AssemblyNeeded;
                oldPC.TotalPrice     = cpu.Price + motherboard.Price + powerSupply.Price + selectedMemories.Sum(item => item.Price * item.Count) + (model.AssemblyNeeded ? 50 : 0);
                //delete old selected memories
                for (int i = 0; i < oldPC.PCMemories.Count; i++)
                {
                    _pcMemoryService.Delete(oldPC.PCMemories.ElementAt(i));
                    i--;
                }
                _unitOfWork.SaveChanges();
                //add new selected memories
                foreach (var item in selectedMemories)
                {
                    var pcMemory = new PCMemory
                    {
                        MemoryId = item.Id,
                        PC       = oldPC,
                        Count    = item.Count
                    };
                    _pcMemoryService.Insert(pcMemory);
                }
                //save and commit all changes
                _unitOfWork.SaveChanges();
                _unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }
            LoadLists();
            return(View(model));
        }
예제 #6
0
파일: PCService.cs 프로젝트: Phylanx/CST356
 private PC ToPc(PCViewModel pc)
 {
     return(new PC
     {
         Id = pc.Id,
         Name = pc.Name,
         GB_Memory = pc.GB_Memory,
         GB_Storage = pc.GB_Storage,
         MHZ_Processor = pc.MHZ_Processor,
         ReadyForUpgrade = pc.ReadyForUpgrade,
         UserId = pc.UserId
     });
 }
예제 #7
0
        private void Update(PCViewModel pc)
        {
            var db = new AppDbContext();

            var pcToUpdate = db.PCs.Find(pc.Id);

            pcToUpdate.Name            = pc.Name;
            pcToUpdate.GB_Memory       = pc.GB_Memory;
            pcToUpdate.GB_Storage      = pc.GB_Storage;
            pcToUpdate.MHZ_Processor   = pc.MHZ_Processor;
            pcToUpdate.ReadyForUpgrade = pc.ReadyForUpgrade;
            pcToUpdate.UserId          = pc.UserId;

            db.SaveChanges();
        }
        public IActionResult Rate(int id)
        {
            var pc = IncludeProperties()
                     .FirstOrDefault(p => p.Id == id);

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

            PCViewModel model = GetModel(pc);

            model.UsersRatedIds = pc.UsersRatedIds;

            return(View(model));
        }
        public IActionResult Details(int id)
        {
            var pc = IncludeProperties()
                     .FirstOrDefault(p => p.Id == id);

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

            RateSystem(pc);

            context.SaveChanges();

            PCViewModel model = GetModel(pc);

            return(View(model));
        }
예제 #10
0
        // GET: PC/Create
        public ActionResult Create()
        {
            //setup new model
            var model = new PCViewModel
            {
                SelectedMemories = _memoryService.All.ToList().Select(item => new MemorySelectViewModel
                {
                    Id               = item.Id,
                    Name             = item.Name,
                    PowerConsumption = item.PowerConsumption,
                    Price            = item.Price
                })
            };

            //load memories,motherboards and cpus
            LoadLists();
            return(View(model));
        }
예제 #11
0
        public async Task <ActionResult> Create([Bind(Include = "Id,CustomerName,CPUId,MotherboardId,PowerSupplyId,AssemblyNeeded,SelectedMemories")] PCViewModel model)
        {
            //get selected parts
            var motherboard      = _motherboardService.Find(model.MotherboardId);
            var cpu              = _cpuService.Find(model.CPUId);
            var powerSupply      = _powerSupplyService.Find(model.PowerSupplyId);
            var selectedMemories = model.SelectedMemories.Where(item => item.IsSelected);

            if (ModelState.IsValid)
            {
                //validate pc configuration
                var message = ValidatePCConfiguration(motherboard, cpu, powerSupply, selectedMemories);
                if (!string.IsNullOrEmpty(message))
                {
                    //not cofigured well
                    ViewBag.ErrorMessage = message;
                    LoadLists();
                    return(View(model));
                }
                //setup a new pc
                var newPC = _mapper.Map <PC>(model);
                //compute the price
                newPC.TotalPrice = cpu.Price + motherboard.Price + powerSupply.Price + selectedMemories.Sum(item => item.Price * item.Count) + (model.AssemblyNeeded ? 50 : 0);
                _pcService.Insert(newPC);

                //get selected memories
                foreach (var item in model.SelectedMemories.Where(item => item.IsSelected))
                {
                    var pcMemory = new PCMemory
                    {
                        MemoryId = item.Id,
                        PC       = newPC,
                        Count    = item.Count
                    };
                    _pcMemoryService.Insert(pcMemory);
                }
                //save the changes
                _unitOfWork.SaveChanges();
                return(RedirectToAction("Index"));
            }
            //if error load lists again
            LoadLists();
            return(View(model));
        }
예제 #12
0
        public HomeController(ILogger <HomeController> logger, IPCRepositiory pcRepo, ICaseRepository caseRepo, ICPURepository cpuRepo, IGPURepository gpuRepo, IHarddriveRepository harddriveRepo, IMotherboardRepository motherboardRepo, IPSURepository psuRepo, IRAMRepository ramRepo)
        {
            _logger          = logger;
            _pcRepo          = pcRepo;
            _caseRepo        = caseRepo;
            _cpuRepo         = cpuRepo;
            _gpuRepo         = gpuRepo;
            _harddriveRepo   = harddriveRepo;
            _motherboardRepo = motherboardRepo;
            _psuRepo         = psuRepo;
            _ramRepo         = ramRepo;

            _pcs              = new PCViewModel();
            _pcs.PCs          = _pcRepo.getPCs().ToList();
            _pcs.Cases        = _caseRepo.getCases().ToList();
            _pcs.CPUs         = _cpuRepo.getCPUs().ToList();
            _pcs.GPUs         = _gpuRepo.getGPUS().ToList();
            _pcs.Harddrives   = _harddriveRepo.getHarddrives().ToList();
            _pcs.Motherboards = _motherboardRepo.getMotherboards().ToList();
            _pcs.PSUs         = _psuRepo.getPSUs().ToList();
            _pcs.RAMs         = _ramRepo.getRAMs().ToList();
        }
예제 #13
0
 public IActionResult Edit(PCViewModel pcvm)
 {
     _pcRepo.updatePC(pcvm.Pc);
     return(RedirectToAction("Index"));
 }
예제 #14
0
        public ActionResult Add(PCViewModel viewmodel)
        {
            ViewBag.LM = db.Stocks.ToList().Where(x => x.category == "PCBox");
            List <Stock>          slist = new List <Stock>(db.Stocks.ToList().Where(x => x.category == "PCBox"));
            List <SelectListItem> li    = new List <SelectListItem>();

            foreach (var item in slist)
            {
                var man = li.Find(x => x.Value == item.manufacturer);
                if (man == null)
                {
                    li.Add(new SelectListItem {
                        Text = item.manufacturer, Value = item.manufacturer
                    });
                }
            }
            ViewBag.PCM = li;
            if (ModelState.IsValid)
            {
                try
                {
                    var stock = db.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) &&
                                                         m.manufacturer.Equals(viewmodel.manufacturer) &&
                                                         m.category.Equals("PCBox"));


                    if (stock != null && stock.quantity != 0)
                    {
                        AssetLogic al    = new AssetLogic();
                        var        asset = new Asset
                        {
                            manufacturer     = viewmodel.manufacturer,
                            serialNumber     = viewmodel.serialNumber,
                            dateadded        = viewmodel.dateAdded,
                            warranty         = viewmodel.warranty + " Months",
                            costprice        = viewmodel.costprice,
                            depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice)
                        };
                        var pc = new PCBox
                        {
                            serialNumber = viewmodel.serialNumber,
                            manufacturer = viewmodel.manufacturer,
                            modelName    = viewmodel.modelName,
                            warranty     = viewmodel.warranty + " Months",
                            dateAdded    = viewmodel.dateAdded,
                            HDD          = viewmodel.HDD,
                            OS           = viewmodel.OS,
                            RAM          = viewmodel.RAM,
                        };
                        stock.quantity = stock.quantity - 1;
                        _repo.Insert(asset, pc);
                        _repo.Save();
                        db.SaveChanges();
                        TempData["Success"] = "Asset has been added!";
                    }
                    else
                    {
                        ViewBag.Message = "Asset not available in stock. Update your stock.";
                    }
                }
                catch (Exception e)
                {
                    ViewBag.Message = "Asset not added. Error: " + e.Message;
                }
            }
            ModelState.Clear();
            return(View(viewmodel));
        }
예제 #15
0
파일: PCService.cs 프로젝트: Phylanx/CST356
 public void SavePC(PCViewModel pc)
 {
     _rep.SavePC(ToPc(pc));
 }
예제 #16
0
 //load lists
 private void LoadLists(PCViewModel model = null)
 {
     ViewBag.MotherboardId = new SelectList(_motherboardService.All, "Id", "Name", model?.MotherboardId);
     ViewBag.CPUId         = new SelectList(_cpuService.All, "Id", "Name", model?.CPUId);
     ViewBag.PowerSupplyId = new SelectList(_powerSupplyService.All, "Id", "Name", model?.PowerSupplyId);
 }