// GET: Products/Details/5 public async Task <IActionResult> Details(string id, bool recommended = false) { if (id == null) { return(NotFound()); } var product = await _context.Computer.FirstOrDefaultAsync(m => m.Id == id); if (product == null) { return(NotFound()); } //StockItem stockItem = await _apiClient.ApiStockGetAsync(product.Id); //ViewBag.AmountInStock = stockItem.AmountInStock; if (recommended) { RecommendationStats recommendationStats = _context.RecommendationStats.FirstOrDefault(); recommendationStats.BoughtCount += 1; _context.RecommendationStats.Update(recommendationStats); _context.Entry(recommendationStats).Property("RecommendedCount").IsModified = false; await _context.SaveChangesAsync(); } return(View(product)); }
public async Task <IActionResult> Edit(Guid id, [Bind("CustomerId,Amount,CardNumber,Currency,CreatedDate,Id")] Account account) { if (id != account.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(account); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AccountExists(account.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id", account.CustomerId); return(View(account)); }
public async Task <IActionResult> Create([Bind("Amount,CreatedDate,Id")] Invoice invoice) { if (ModelState.IsValid) { invoice.Id = Guid.NewGuid(); _context.Add(invoice); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(invoice)); }
public async Task <IActionResult> Create([Bind("Surname,Name,Phone,Passport,SecondName,Email,CreatedDate,Id")] Customer customer) { if (ModelState.IsValid) { customer.Id = Guid.NewGuid(); _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CategoryId,Price,ImageLink,CreatedDate,Id")] Kit kit) { if (ModelState.IsValid) { kit.Id = Guid.NewGuid(); _context.Add(kit); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", kit.CategoryId); return(View(kit)); }
public async Task <IActionResult> Create([Bind("KitId,Name,Value,CreatedDate,Id")] Description description) { if (ModelState.IsValid) { description.Id = Guid.NewGuid(); _context.Add(description); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["KitId"] = new SelectList(_context.Kits, "Id", "Id", description.KitId); return(View(description)); }
public async Task <IActionResult> Create([Bind("KitId,OrderId,Quantity,CreatedDate,Id")] OrderItem orderItem) { if (ModelState.IsValid) { orderItem.Id = Guid.NewGuid(); _context.Add(orderItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["KitId"] = new SelectList(_context.Kits, "Id", "Id", orderItem.KitId); ViewData["OrderId"] = new SelectList(_context.Orders, "Id", "Id", orderItem.OrderId); return(View(orderItem)); }
public async Task <IActionResult> Create([Bind("InvoiceId,AccountId,Quantity,Status,CreatedDate,Id")] Order order) { if (ModelState.IsValid) { order.Id = Guid.NewGuid(); _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["AccountId"] = new SelectList(_context.Accounts, "Id", "Id", order.AccountId); //ViewData["InvoiceId"] = new SelectList(_context.Invoices, "Id", "Id", order.InvoiceId); return(View(order)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Name,CreatedDate,Id")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Database.ExecuteSqlInterpolated($"dbo.CategoryUpdate {category.Id},{category.Name}"); _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Index(RecommendationViewModel recommendationViewModel) { if (ModelState.IsValid) { Computer requestedComputer = recommendationViewModel.RequestedComputer; int requestedCores = recommendationViewModel.CoresNotImportant ? 0 : requestedComputer.Cores; double requestedCpuClockSpeed = recommendationViewModel.ClockSpeedNotImportant ? 0 : requestedComputer.ClockSpeed; int requestedRAM = recommendationViewModel.RAMNotImportant ? 0 : requestedComputer.RAM; int requestedStorage = recommendationViewModel.StorageNotImportant ? 0 : requestedComputer.Storage; double requestedPrice = recommendationViewModel.PriceNotImportant ? 0 : requestedComputer.Price; double coresPriority = recommendationViewModel.CoresNotImportant ? 0 : recommendationViewModel.CorePriority; double clockSpeedPriority = recommendationViewModel.ClockSpeedNotImportant ? 0 : recommendationViewModel.ClockSpeedPriority; double ramPriority = recommendationViewModel.RAMNotImportant ? 0 : recommendationViewModel.RAMPriority; double storagePriority = recommendationViewModel.StorageNotImportant ? 0 : recommendationViewModel.StoragePriority; double pricePriority = recommendationViewModel.PriceNotImportant ? 0 : recommendationViewModel.PricePriority; IList <Computer> computers = await _context.Computer .Where(c => c.CategoryId == requestedComputer.CategoryId) .ToListAsync(); RecommendationStats recommendationStats = _context.RecommendationStats.FirstOrDefault(); recommendationStats.RecommendedCount += 1; _context.RecommendationStats.Update(recommendationStats); _context.Entry(recommendationStats).Property("BoughtCount").IsModified = false; await _context.SaveChangesAsync(); IDictionary <double, Computer> offers = new Dictionary <double, Computer>(); foreach (Computer computer in computers) { double distance = Math.Sqrt(coresPriority * Math.Pow(requestedCores - computer.Cores, 2) + clockSpeedPriority * Math.Pow(requestedCpuClockSpeed - computer.ClockSpeed, 2) + ramPriority * Math.Pow(requestedRAM - computer.RAM, 2) + storagePriority * Math.Pow(requestedStorage - computer.Storage, 2) + pricePriority * Math.Pow(requestedPrice - computer.Price, 2)); offers.Add(distance, computer); } IOrderedEnumerable <KeyValuePair <double, Computer> > sortedOffers = offers.OrderBy(key => key.Key); Computer bestOffer = sortedOffers.FirstOrDefault().Value; bestOffer.Category = _context.Category.Where(c => c.Id == bestOffer.CategoryId).FirstOrDefault(); recommendationViewModel.RecommendedComputer = bestOffer; } ViewData["CategoryId"] = new SelectList(await _context.Category.ToListAsync(), "Id", "Name"); return(View(recommendationViewModel)); }
public async Task <IActionResult> Create() { if (_signInManager.IsSignedIn(User) == false) { return(Redirect("/Identity/Account/Login")); } try { string userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); Order order = new Order() { UserId = userId, CartItems = SessionHelper.ReadFromSession <List <CartItem> >(HttpContext.Session, "cart"), CreationDate = DateTime.Now, Status = Status.AwaitingFulfillment }; double orderTotal = 0; foreach (CartItem cartItem in order.CartItems) { orderTotal += cartItem.Total; cartItem.Id = ""; } order.Total = orderTotal; _context.Order.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction("IndexByUserId", new { userId = userId })); } catch { return(RedirectToAction("Index", "Cart")); } }