/// <summary> /// Deletes selected motherboard. /// </summary> /// <param name="obj"></param> private async void ExecDeleteMotherboardAsync(object obj) { Motherboard motherboard = (Motherboard)ProductListView.ProductListUserControl.MotherboardList.SelectedItem; Motherboards.Remove(motherboard); switch (App.DataSource) { case ConnectionResource.LOCALAPI: await new WebServiceManager <Motherboard>().DeleteAsync(motherboard); break; case ConnectionResource.LOCALMYSQL: using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL)) { ctx.DbSetMotherboards.Attach(motherboard); ctx.DbSetMotherboards.Remove(motherboard); await ctx.SaveChangesAsync(); } break; default: break; } }
public IEnumerable <Good> GetGoodsDependsOnFilter(string category, PcComponentsFilter filter) { switch (category) { case "Процессоры": return(Processors.GetAll(filter)); case "Материнские платы": return(Motherboards.GetAll(filter)); case "Видеокарты": return(VideoCards.GetAll(filter)); case "Корпуса": return(ComputerСases.GetAll(filter)); case "Модули памяти": return(MemoryModules.GetAll(filter)); case "Блоки питания": return(PowerSupplies.GetAll(filter)); case "SSD диски": return(SSDDrives.GetAll(filter)); default: return(null); } }
public ActionResult DeleteConfirmed(int id) { Motherboards motherboards = db.Motherboards.Find(id); db.Motherboards.Remove(motherboards); db.SaveChanges(); return(RedirectToAction("Index")); }
private int GetMotherboardIndex(Motherboard motherboard) { foreach (Motherboard m in Motherboards) { if (m.Id == motherboard.Id) { return(Motherboards.IndexOf(m)); } } return(-1); }
public ActionResult Edit([Bind(Include = "Id,Name,Price,Delivery,Order,Maker")] Motherboards motherboards) { if (ModelState.IsValid) { db.Entry(motherboards).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Delivery = new SelectList(db.Deliveries, "Id", "date", motherboards.Delivery); ViewBag.Maker = new SelectList(db.Makers, "Id", "Name", motherboards.Maker); ViewBag.Order = new SelectList(db.Orders, "Id", "date", motherboards.Order); return(View(motherboards)); }
// GET: Motherboards/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Motherboards motherboards = db.Motherboards.Find(id); if (motherboards == null) { return(HttpNotFound()); } return(View(motherboards)); }
// GET: Motherboards/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Motherboards motherboards = db.Motherboards.Find(id); if (motherboards == null) { return(HttpNotFound()); } ViewBag.Delivery = new SelectList(db.Deliveries, "Id", "date", motherboards.Delivery); ViewBag.Maker = new SelectList(db.Makers, "Id", "Name", motherboards.Maker); ViewBag.Order = new SelectList(db.Orders, "Id", "date", motherboards.Order); return(View(motherboards)); }
/// <summary> /// Removes a product from the cart. /// </summary> /// <param name="obj"></param> public void ExecRemoveFromCart(object obj) { CartItem cartItem = (CartItem)CartView.CartUC.Cart.SelectedItem; cartItem.Product.Stock += cartItem.Quantity; Cart.Total -= cartItem.Price; Cart.Items.Remove(cartItem); cartItem.Cart = null; if (cartItem.Product is CPU) { CPUs.Add((CPU)cartItem.Product); } else if (cartItem.Product is GPU) { GPUs.Add((GPU)cartItem.Product); } else if (cartItem.Product is Motherboard) { Motherboards.Add((Motherboard)cartItem.Product); } else if (cartItem.Product is Memory) { Rams.Add((Memory)cartItem.Product); } else if (cartItem.Product is Storage) { StorageComponents.Add((Storage)cartItem.Product); } else if (cartItem.Product is PSU) { PSUs.Add((PSU)cartItem.Product); } else // Case { Cases.Add((Case)cartItem.Product); } }
/// <summary> /// Processes the payment. /// Stock of products decreased, customer gets charged. /// </summary> /// <param name="obj"></param> private async void ExecProceedToPaymentAsync(object obj) { Cart.Customer.Money -= Cart.Total; switch (App.DataSource) { case ConnectionResource.LOCALAPI: await new WebServiceManager <Cart>().PostAsync(Cart); break; case ConnectionResource.LOCALMYSQL: using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL)) { ctx.Entry(Cart.Customer).State = EntityState.Modified; foreach (var item in Cart.Items) { ctx.Entry(item.Product).State = EntityState.Modified; } ctx.DbSetCarts.Add(Cart); await ctx.SaveChangesAsync(); } break; default: break; } foreach (var item in Cart.Items) { if (item.Product.Stock > 0) { if (item.Product is CPU) { CPUs.Add((CPU)item.Product); } else if (item.Product is GPU) { GPUs.Add((GPU)item.Product); } else if (item.Product is Motherboard) { Motherboards.Add((Motherboard)item.Product); } else if (item.Product is Memory) { Rams.Add((Memory)item.Product); } else if (item.Product is Storage) { StorageComponents.Add((Storage)item.Product); } else if (item.Product is PSU) { PSUs.Add((PSU)item.Product); } else // Case { Cases.Add((Case)item.Product); } } } Cart.Items.Clear(); Cart.Total = 0; }
/// <summary> /// Adds the selected product to the cart's items. /// </summary> /// <param name="obj"></param> private void ExecAddToCart(object obj) { ProductListUserControl productListUC = CartView.CartUC.ProductsUC; CartItem cartItem = new CartItem(); cartItem.Cart = Cart; cartItem.Quantity = 1; if (productListUC.CPUList.SelectedIndex != -1) // CPU { CPU cpu = (CPU)productListUC.CPUList.SelectedItem; CPUs.Remove(cpu); cartItem.Product = cpu; cartItem.Price = cpu.Price; } else if (productListUC.GPUList.SelectedIndex != -1) // GPU { GPU gpu = (GPU)productListUC.GPUList.SelectedItem; GPUs.Remove(gpu); cartItem.Product = gpu; cartItem.Price = gpu.Price; } else if (productListUC.MotherboardList.SelectedIndex != -1) // Motherboard { Motherboard motherboard = (Motherboard)productListUC.MotherboardList.SelectedItem; Motherboards.Remove(motherboard); cartItem.Product = motherboard; cartItem.Price = motherboard.Price; } else if (productListUC.MemoryList.SelectedIndex != -1) // Memory { Memory memory = (Memory)productListUC.MemoryList.SelectedItem; Rams.Remove(memory); cartItem.Product = memory; cartItem.Price = memory.Price; } else if (productListUC.StorageList.SelectedIndex != -1) // Storage { Storage storage = (Storage)productListUC.StorageList.SelectedItem; StorageComponents.Remove(storage); cartItem.Product = storage; cartItem.Price = storage.Price; } else if (productListUC.PSUList.SelectedIndex != -1) // PSU { PSU psu = (PSU)productListUC.PSUList.SelectedItem; PSUs.Remove(psu); cartItem.Product = psu; cartItem.Price = psu.Price; } else // Case { Case pcCase = (Case)productListUC.CaseList.SelectedItem; Cases.Remove(pcCase); cartItem.Product = pcCase; cartItem.Price = pcCase.Price; } cartItem.Product.Stock--; Cart.Total += cartItem.Price; Cart.Items.Add(cartItem); }
public void GenerateData() { Case u1 = new Case() { Model = "SysUniCa2000", Name = "SystemUnitCase", Price = 2000, Length = 200, Width = 100, Height = 50, }; Case u2 = new Case() { Model = "SysUniCa150", Name = "SystemUnitCase", Price = 1500, Length = 120, Width = 120, Height = 50, }; Case u3 = new Case() { Model = "SysUniCa3000", Name = "SystemUnitCase", Price = 1000, Length = 100, Width = 80, Height = 30, }; u1.MotherboardTypesSupported.Add(MotherboardTypes.MBT100); u1.MotherboardTypesSupported.Add(MotherboardTypes.MBT200); u1.MotherboardTypesSupported.Add(MotherboardTypes.MBT300); u1.MotherboardTypesSupported.Add(MotherboardTypes.MBT500); u2.MotherboardTypesSupported.Add(MotherboardTypes.MBT400); u2.MotherboardTypesSupported.Add(MotherboardTypes.MBT500); u2.MotherboardTypesSupported.Add(MotherboardTypes.MBT600); u3.MotherboardTypesSupported.Add(MotherboardTypes.MBT700); u3.MotherboardTypesSupported.Add(MotherboardTypes.MBT400); u3.MotherboardTypesSupported.Add(MotherboardTypes.MBT300); u3.MotherboardTypesSupported.Add(MotherboardTypes.MBT600); Cases.Add(u1.Id, u1); Cases.Add(u2.Id, u2); Cases.Add(u3.Id, u3); Motherboard m1 = new Motherboard() { Type = MotherboardTypes.MBT100, Model = "M1", Name = "Motherboard M1", Price = 600 }; Motherboard m2 = new Motherboard() { Type = MotherboardTypes.MBT200, Model = "M2", Name = "Motherboard M2", Price = 500 }; Motherboard m3 = new Motherboard() { Type = MotherboardTypes.MBT300, Model = "M3", Name = "Motherboard M3", Price = 300 }; Motherboard m4 = new Motherboard() { Type = MotherboardTypes.MBT500, Model = "M4", Name = "Motherboard M4", Price = 1000 }; Motherboard m5 = new Motherboard() { Type = MotherboardTypes.MBT700, Model = "M5", Name = "Motherboard M5", Price = 1400 }; m1.ProcessorTypesSupported.Add(ProcessorTypes.PT1); m1.ProcessorTypesSupported.Add(ProcessorTypes.PT2); m1.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT1); m1.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT2); m1.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT5); m2.ProcessorTypesSupported.Add(ProcessorTypes.PT3); m2.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT4); m3.ProcessorTypesSupported.Add(ProcessorTypes.PT4); m3.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT1); m3.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT3); m4.ProcessorTypesSupported.Add(ProcessorTypes.PT4); m4.ProcessorTypesSupported.Add(ProcessorTypes.PT5); m4.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT5); m4.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT5); m5.ProcessorTypesSupported.Add(ProcessorTypes.PT2); m5.ProcessorTypesSupported.Add(ProcessorTypes.PT3); m5.ProcessorTypesSupported.Add(ProcessorTypes.PT4); m5.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT2); m5.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT3); m5.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT4); m5.MemoryCardTypesSupported.Add(MemoryCardTypes.MCT5); Motherboards.Add(m1.Id, m1); Motherboards.Add(m2.Id, m2); Motherboards.Add(m3.Id, m3); Motherboards.Add(m4.Id, m4); Motherboards.Add(m5.Id, m5); Processor p1 = new Processor() { Type = ProcessorTypes.PT1, NumberOfCores = 4, Name = "Processor PT1 4 cores", Model = "P1", Price = 300, Architecture = "A1", ClockRate = 4, PowerConsumption = 400 }; Processor p2 = new Processor() { Type = ProcessorTypes.PT1, NumberOfCores = 8, Name = "Processor PT1 8 cores", Model = "P2", Price = 400, Architecture = "A1", ClockRate = 3, PowerConsumption = 500 }; Processor p3 = new Processor() { Type = ProcessorTypes.PT2, NumberOfCores = 4, Name = "Processor PT2 4 cores", Model = "P3", Price = 2000, Architecture = "A2", ClockRate = 5, PowerConsumption = 600 }; Processor p4 = new Processor() { Type = ProcessorTypes.PT3, NumberOfCores = 16, Name = "Processor PT3 16 cores", Model = "P4", Price = 5000, Architecture = "A3", ClockRate = 8, PowerConsumption = 700 }; Processors.Add(p1.Id, p1); Processors.Add(p2.Id, p2); Processors.Add(p3.Id, p3); Processors.Add(p4.Id, p4); MemoryCard c1 = new MemoryCard() { Type = MemoryCardTypes.MCT1, Name = "Memory Card MCT1", Model = "MC 1 1024", Price = 2000, MemoryCapacity = 1024 }; MemoryCard c2 = new MemoryCard() { Type = MemoryCardTypes.MCT4, Name = "Memory Card MCT4", Model = "MC 2 2048", Price = 3200, MemoryCapacity = 2048 }; MemoryCard c3 = new MemoryCard() { Type = MemoryCardTypes.MCT5, Name = "Memory Card MCT5", Model = "MC 3 1024", Price = 1200, MemoryCapacity = 1024 }; MemoryCard c4 = new MemoryCard() { Type = MemoryCardTypes.MCT3, Name = "Memory Card MCT3", Model = "MC 3 512", Price = 700, MemoryCapacity = 512 }; MemoryCard c5 = new MemoryCard() { Type = MemoryCardTypes.MCT1, Name = "Memory Card MCT1", Model = "MC 1 1024", Price = 1700, MemoryCapacity = 1024 }; MemoryCards.Add(c1.Id, c1); MemoryCards.Add(c2.Id, c2); MemoryCards.Add(c3.Id, c3); MemoryCards.Add(c4.Id, c4); MemoryCards.Add(c5.Id, c5); PowerSource s1 = new PowerSource() { Name = "PS1000", Length = 120, Width = 100, Height = 10, Power = 4500, Price = 500, Model = "SPS 4500", VoltageDropsProtection = true }; PowerSource s2 = new PowerSource() { Name = "PS1000", Length = 80, Width = 80, Height = 20, Power = 4200, Price = 700, Model = "SPS 4200", VoltageDropsProtection = true }; PowerSource s3 = new PowerSource() { Name = "PS1000", Length = 100, Width = 90, Height = 10, Power = 5000, Price = 500, Model = "SPS 5000", VoltageDropsProtection = false }; PowerSource s4 = new PowerSource() { Name = "PS1000", Length = 120, Width = 120, Height = 15, Power = 4500, Price = 400, Model = "SPS 4500", VoltageDropsProtection = false }; PowerSources.Add(s1.Id, s1); PowerSources.Add(s2.Id, s2); PowerSources.Add(s3.Id, s3); PowerSources.Add(s4.Id, s4); }