public async Task <IActionResult> AddToCart(Atractions attraction) { var order = await _context.Orders .SingleOrDefaultAsync(m => m.Atractions.Id == attraction.Id); var att = await _context.Atractions .SingleOrDefaultAsync(m => m.Id == attraction.Id); if (order == null) { Orders newOrder = new Orders(); newOrder.Atractions = att; newOrder.NumOfTickets = 1; newOrder.Time = DateTime.Now; newOrder.TotalCost = att.TicketPrice; _context.Add(newOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { order.NumOfTickets++; order.Time = DateTime.Now; order.TotalCost += att.TicketPrice; _context.Update(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Kind,State,Address,Age,Date,DurationTime")] Atractions atractions) { if (id != atractions.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(atractions); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AtractionsExists(atractions.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(atractions)); }
public async Task <IActionResult> Create([Bind("Id,Name,Kind,State,Address,Age,Date,DurationTime")] Atractions atractions) { if (ModelState.IsValid) { _context.Add(atractions); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(atractions)); }