// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string PerformanceId, string PerformanceDateId) { if (!User.Identity.IsAuthenticated) { return(Redirect("/Identity/Account/Login?returnUrl=/Purchases/New")); } if (!ModelState.IsValid) { return(Page()); } Performance = Context.Performances.FirstOrDefault(x => x.Id == PerformanceId); long seatId = Context.Purchases.Count(x => x.PerformanceId == Performance.Id) + 1; if (seatId > Context.Theatres.FirstOrDefault(x => x.Id == Performance.TheatreId).Seats) { return(Page()); } Purchases.Id = Guid.NewGuid().ToString(); Purchases.PerformanceId = PerformanceId; Purchases.UserId = UserManager.GetUserId(User); Purchases.ConcurrencyStamp = Guid.NewGuid().ToString(); Purchases.Purchased = DateTime.Now; Purchases.Edited = DateTime.Now; Purchases.AmountPaid = Context.Performances.First(x => x.Id == Performance.Id).Price; Purchases.SeatId = seatId; Context.Purchases.Add(Purchases); await Context.SaveChangesAsync(); return(Redirect("/Purchases/List")); }
public async Task <IActionResult> OnGetAsync(string id) { if (!User.IsInRole(Constants.Bookkeeper) && !User.IsInRole(Constants.Administrator)) { return(NotFound()); } if (id == null) { return(NotFound()); } Performances = await Context.Performances .Include(p => p.Theatre).FirstOrDefaultAsync(m => m.Id == id); if (Performances == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(string id) { if (!User.IsInRole(Constants.Bookkeeper) && !User.IsInRole(Constants.Administrator)) { return(NotFound()); } if (id == null) { return(NotFound()); } Performances = await Context.Performances.FindAsync(id); if (Performances != null) { Context.Performances.Remove(Performances); await Context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }