public async void GetGraphicsCardsFromDatabaseTest()
        {
            var options = new DbContextOptionsBuilder <CheapWareContext>()
                          .UseInMemoryDatabase(databaseName: "GetGraphicscardsFromDatabase")
                          .Options;
            var graphicscard = new GraphicsCards {
                Name = "test name", Speed = "1700 Mghz", Size = "8GB", Price = 300.99M
            };
            List <GraphicsCard> listofgraphicscards = null;

            using (var context = new CheapWareContext(options))
            {
                context.Add(graphicscard);
                context.SaveChanges();
            }

            using (var context = new CheapWareContext(options))
            {
                var service = new ComputerRepo(context);
                listofgraphicscards = await service.GetGraphicsCards();
            }


            using (var context = new CheapWareContext(options))
            {
                Assert.Single(listofgraphicscards);
                Assert.Equal("test name", context.GraphicsCards.Single().Name);
            }
        }
        public async Task <ActionResult> Create(GraphicsCards gc)
        {
            try
            {
                string jsonString = JsonConvert.SerializeObject(gc);

                var request = new HttpRequestMessage(HttpMethod.Post, "api/graphicscards");
                {
                    // 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());
            }
        }
 private int GetGraphicsCardIndex(GraphicCard graphicCard)
 {
     foreach (GraphicCard g in GraphicsCards)
     {
         if (g.Id == graphicCard.Id)
         {
             return(GraphicsCards.IndexOf(g));
         }
     }
     return(-1);
 }
        // GET: Inventorys/Details/5
        public async Task <ActionResult> Details(string name)
        {
            var request = CreateRequestToService(HttpMethod.Get, "api/graphicscards/" + name);

            try
            {
                var response = await HttpClient.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    return(View("Error"));
                }
                string jsonString = await response.Content.ReadAsStringAsync();

                GraphicsCards gc = JsonConvert.DeserializeObject <GraphicsCards>(jsonString);

                return(View(gc));
            }
            catch (HttpRequestException)
            {
                return(View("Error"));
            }
        }