public async void GetRAMsFromDatabaseTest() { var options = new DbContextOptionsBuilder <CheapWareContext>() .UseInMemoryDatabase(databaseName: "GetRamsFromDatabase") .Options; var ram = new Rams { Name = "test name", Speed = "2600Mhrtz", Size = "16GB", Price = 300.99M }; List <Ram> listoframs = null; using (var context = new CheapWareContext(options)) { context.Add(ram); context.SaveChanges(); } using (var context = new CheapWareContext(options)) { var service = new ComputerRepo(context); listoframs = await service.GetRams(); } using (var context = new CheapWareContext(options)) { Assert.Single(listoframs); Assert.Equal("test name", context.Rams.Single().Name); } }
public async void GetRamByNameTest() { var options = new DbContextOptionsBuilder <CheapWareContext>() .UseInMemoryDatabase(databaseName: "GetRamByNameDatabase") .Options; var ram1 = new Rams { Name = "test name1", Speed = "1700 Mghrtz", Size = "8GB", Price = 110.99M }; var ram2 = new Rams { Name = "test name2", Speed = "1900 Mghrtz", Size = "16GB", Price = 150.99M }; Ram ram = null; using (var context = new CheapWareContext(options)) { context.Add(ram1); context.Add(ram2); context.SaveChanges(); } using (var context = new CheapWareContext(options)) { var service = new ComputerRepo(context); ram = await service.GetRamByName("test name1"); } using (var context = new CheapWareContext(options)) { Assert.Equal("1700 Mghrtz", ram.Speed); Assert.Equal("8GB", ram.Size); Assert.Equal(110.99M, ram.Price); } }
public override string ToString() { StringBuilder builder = new StringBuilder(); builder.AppendLine($"Computer type: {Name}"); builder.AppendLine("Current configuration:"); builder.AppendLine($" CPU: {Cpus.ToStatus()}"); builder.AppendLine($" Storage: {Hards.ToStatus()}"); builder.AppendLine($" RAM: {Rams.ToStatus()}"); builder.AppendLine($" GPU: {Gpus.ToStatus()}"); builder.AppendLine($" Network: {Networks.ToStatus()}"); builder.AppendLine($" Wireless: {Wirelesses.ToStatus()}"); builder.AppendLine($" Sources: {Sources.ToStatus()}"); builder.AppendLine($" Motherboard: {Motherboard}"); string motherboardLoad = GetMotherboardLoadString(); builder.AppendLine($"Motherboard configuration: {motherboardLoad}"); int currentLoad = GetSourceLoad(); int maximumLoad = MaximumSourceLoad(); float percentageLoad = (float)currentLoad / maximumLoad; builder.AppendLine($"Current source load: {currentLoad}/{maximumLoad} - {percentageLoad:00.##}"); return(builder.ToString()); }
/// <summary> /// Deletes selected memory. /// </summary> /// <param name="obj"></param> private async void ExecDeleteMemoryAsync(object obj) { Memory memory = (Memory)ProductListView.ProductListUserControl.MemoryList.SelectedItem; Rams.Remove(memory); switch (App.DataSource) { case ConnectionResource.LOCALAPI: await new WebServiceManager <Memory>().DeleteAsync(memory); break; case ConnectionResource.LOCALMYSQL: using (var ctx = new MysqlDbContext(ConnectionResource.LOCALMYSQL)) { ctx.DbSetMemories.Attach(memory); ctx.DbSetMemories.Remove(memory); await ctx.SaveChangesAsync(); } break; default: break; } }
public async Task <ActionResult> Create(Rams ram) { try { string jsonString = JsonConvert.SerializeObject(ram); var request = new HttpRequestMessage(HttpMethod.Post, "api/rams"); { // we set what the Content-Type header will be here request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json"); }; var response = await HttpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { return(View("Error")); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult DeleteConfirmed(int id) { Rams rams = db.Rams.Find(id); db.Rams.Remove(rams); db.SaveChanges(); return(RedirectToAction("Index")); }
private int GetSourceLoad() { return(Rams.Select(x => x.LoadUsage).Sum() + Hards.Select(x => x.LoadUsage).Sum() + Cpus.Select(x => x.LoadUsage).Sum() + Gpus.Select(x => x.LoadUsage).Sum() + Networks.Select(x => x.LoadUsage).Sum() + Wirelesses.Select(x => x.LoadUsage).Sum() + Motherboard.LoadUsage); }
private int GetRamIndex(Ram ram) { foreach (Ram r in Rams) { if (r.Id == ram.Id) { return(Rams.IndexOf(r)); } } return(-1); }
public ActionResult Edit([Bind(Include = "Id,Name,Price,Delivery,Order,Maker")] Rams rams) { if (ModelState.IsValid) { db.Entry(rams).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Delivery = new SelectList(db.Deliveries, "Id", "date", rams.Delivery); ViewBag.Maker = new SelectList(db.Makers, "Id", "Name", rams.Maker); ViewBag.Order = new SelectList(db.Orders, "Id", "date", rams.Order); return(View(rams)); }
// GET: Rams/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Rams rams = db.Rams.Find(id); if (rams == null) { return(HttpNotFound()); } return(View(rams)); }
// GET: Rams/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Rams rams = db.Rams.Find(id); if (rams == null) { return(HttpNotFound()); } ViewBag.Delivery = new SelectList(db.Deliveries, "Id", "date", rams.Delivery); ViewBag.Maker = new SelectList(db.Makers, "Id", "Name", rams.Maker); ViewBag.Order = new SelectList(db.Orders, "Id", "date", rams.Order); return(View(rams)); }
/// <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); } }
// GET: Inventorys/Details/5 public async Task <ActionResult> Details(string name) { var request = CreateRequestToService(HttpMethod.Get, "api/rams/" + name); try { var response = await HttpClient.SendAsync(request); if (!response.IsSuccessStatusCode) { return(View("Error")); } string jsonString = await response.Content.ReadAsStringAsync(); Rams ram = JsonConvert.DeserializeObject <Rams>(jsonString); return(View(ram)); } catch (HttpRequestException) { return(View("Error")); } }
/// <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); }