public async Task <IActionResult> Delete(int id) { var @event = await _eventContext.Events.FindAsync(id); _eventContext.Remove(@event); await _eventContext.SaveChangesAsync(); return(RedirectToAction(nameof(EventIndex))); }
public async Task <IActionResult> Create([Bind("CustomerId,EventId,Attended")] GuestBooking guestBooking) { if (ModelState.IsValid) { var existingGuest = _context.Guests.Where(g => g.CustomerId == guestBooking.CustomerId && g.EventId == guestBooking.EventId).ToList(); if ((existingGuest == null || existingGuest.Count == 0) && guestBooking.Attended == true) { var allGuests = _context.Guests.Where(g => g.EventId == guestBooking.EventId).ToList(); EventVM eventVM = new EventVM(await _context.Events.FindAsync(guestBooking.EventId)); if (allGuests.Count >= eventVM.VenueCapacity) { return(BadRequest()); } guestBooking.Attended = false; _context.Add(guestBooking); await _context.SaveChangesAsync(); return(Ok()); } else if (existingGuest != null && existingGuest.Count != 0 && guestBooking.Attended == false) { _context.Remove(existingGuest.FirstOrDefault()); await _context.SaveChangesAsync(); return(Ok()); } } return(BadRequest()); }
public async Task Delete(int id) { Event toDelete = _eventsDbContext.Events.Find(id); _eventsDbContext.Remove(toDelete); await _eventsDbContext.SaveChangesAsync(); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Create([Bind("StaffId,EventId,Attended")] StaffBookingVM staffAttendance) { if (ModelState.IsValid) { try { Staffing staff = await _context.Staffing.FindAsync(staffAttendance.StaffId, staffAttendance.EventId); if (staff != null && staffAttendance.Attended == false) { _context.Remove(staff); await _context.SaveChangesAsync(); return(Ok()); } if (staff == null && staffAttendance.Attended == true) { _context.Add(new Staffing(staffAttendance.EventId, staffAttendance.StaffId)); await _context.SaveChangesAsync(); return(Ok()); } } catch (DbUpdateConcurrencyException) { } } return(NotFound()); }
public async Task <IActionResult> DeleteConfirmed(int id) { var @event = await _dataAccess.GetEvents().FirstOrDefaultAsync(e => e.Id == id); _context.Remove(@event); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> DeleteConfirmed(int id) { var customer = await _context.Customers.FindAsync(id); _context.Remove(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Delete(Guid id) { _db.Remove(new Event { Id = id }); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void DeleteEvent(int id) { var sportEvent = db.Events.Find(id); if (sportEvent == null) { return; } db.Remove(sportEvent); db.SaveChanges(); }
/// <summary> /// HTTP GET endpoint of "Events/RemoveStaff/<paramref name="Id"/>?StaffId=<paramref name="StaffId"/>". <para/> /// Removes a staff member via their <paramref name="StaffId"/> to the <see cref="Event"/> via its <paramref name="Id"/>. /// </summary> /// <param name="Id">The <see cref="Event"/>'s Id.</param> /// <param name="StaffId">The <see cref="Data.Staff"/>'s Id.</param> /// <returns>Takes the user to the <see cref="Staff"/> page.</returns> public async Task <IActionResult> RemoveStaff(int?id, int StaffId) { if (!id.HasValue) { return(NotFound()); } var ev = await _context.EventStaff.FindAsync(StaffId, id); if (ev == null) { return(RedirectToAction(nameof(Staff), new { id })); } _context.Remove(ev); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Staff), new { id })); }
public async Task <IActionResult> Cancel(int id) { var @event = await _context.Events.Include(e => e.StaffBookings).FirstOrDefaultAsync(m => m.Id == id); if (@event.VenueCode != null) { HttpClient client1 = new HttpClient(); var VenueBuilder = new UriBuilder("http://localhost"); VenueBuilder.Port = 23652; VenueBuilder.Path = "api/Reservations/" + @event.VenueCode; client1.DefaultRequestHeaders.Accept.ParseAdd("application/json"); string url = VenueBuilder.ToString(); HttpResponseMessage response1 = await client1.DeleteAsync(url); if (response1.IsSuccessStatusCode) { @event.VenueCode = null; _context.Update(@event); await _context.SaveChangesAsync(); } } if (@event.StaffBookings.Count() > 0) { foreach (StaffBooking s in @event.StaffBookings) { _context.Remove(s); } await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public bool Delete(T item) { context.Remove <T>(item); context.SaveChanges(); return(true); }