public Model.Ulaznice Delete(int id) { var entity = _context.Ulaznice.Find(id); _context.Remove(entity); _context.SaveChanges(); return(_mapper.Map <Model.Ulaznice>(entity)); }
public Model.Korisnici Delete(int id) { var entity = _context.Korisnici.Find(id); _context.Remove(entity); _context.SaveChanges(); return(_mapper.Map <Model.Korisnici>(entity)); }
public virtual TModel Delete(int id) { var entity = _context.Set <TDatabase>().Find(id); _context.Remove(entity); _context.SaveChanges(); return(_mapper.Map <TModel>(entity)); }
public async Task <ActionResult <Movie> > DeleteMovie(int id) { var movie = context.Movies.FirstOrDefault(m => m.MovieId == id); if (movie == null) { return(NotFound()); } context.Remove(movie); await context.SaveChangesAsync(); return(new OkObjectResult(movie)); }
public async Task <ActionResult <ActionResult <Screening> > > DeleteScreening(int id) { var screening = context.Screenings.FirstOrDefault(s => s.ScreeningId == id); if (screening == null) { return(NotFound()); } context.Remove(screening); await context.SaveChangesAsync(); return(new OkObjectResult(screening)); }
public async Task <ActionResult <ScreeningRoom> > DeleteScreeningRoom(int id) { var room = context.ScreeningRooms.FirstOrDefault(m => m.ScreeningRoomId == id); if (room == null) { return(NotFound()); } context.Remove(room); await context.SaveChangesAsync(); return(new OkObjectResult(room)); }
public async Task <IActionResult> DeleteUser(string id) { var user = context.Users.FirstOrDefault(u => u.Id == id); if (user == null) { return(NotFound()); } var response = new UserViewModel(user, encoder); context.Remove(user); await context.SaveChangesAsync(); return(new OkObjectResult(response)); }
public async Task <IActionResult> CheckReservation([FromBody] int reservationId) { var myReservation = context.Reservations.FirstOrDefault(r => r.ReservationId == reservationId); if (myReservation == null) { return(new OkObjectResult("RESERVATION_BOOKED")); } if (myReservation.Expiration.HasValue) { return(BadRequest()); // nie warto sprawdzać potwierdzonej rezerwacji } var otherReservations = context.Reservations .Where(r => r.ScreeningId == myReservation.ScreeningId && r.SeatX == myReservation.SeatX && r.SeatY == myReservation.SeatY); var confirmed = await otherReservations.Where(r => r.IsConfirmed).FirstOrDefaultAsync(); // no niestety if (confirmed != null) { return(new OkObjectResult("RESERVATION_BOOKED")); } var leader = await otherReservations.Where(r => r.Expiration.HasValue).FirstOrDefaultAsync(); if (leader == null) // leader sobie poszedł { var min = otherReservations.Select(r => r.Priority).Min(); // wybieramy z najniższą wartością if (myReservation.Priority == min) // to my! { myReservation.Expiration = DateTime.Now.AddMinutes(1); context.Update(myReservation); await context.SaveChangesAsync(); return(new OkObjectResult(myReservation)); } else { return(new OkObjectResult("KEEP_WAITING")); // nie my, ale warto dalej próbować } } else // leader istnieje { if (leader.Expiration.Value > DateTime.Now) // i dalej ma prawo wyboru { return(new OkObjectResult("KEEP_WAITING")); } else { context.Remove(leader); // leader is dead! await context.SaveChangesAsync(); var min = otherReservations.Select(r => r.Priority).Min(); // wybieramy z najniższ wartości if (myReservation.Priority == min) { myReservation.Expiration = DateTime.Now.AddMinutes(1); context.Update(myReservation); await context.SaveChangesAsync(); return(new OkObjectResult(myReservation)); } else { if (leader.IsConfirmed)// jest rezerwacja zaklepana { var res = otherReservations.Where(r => !r.IsConfirmed); context.RemoveRange(res); await context.SaveChangesAsync(); return(new OkObjectResult("RESERVATION_BOOKED")); } else { return(new OkObjectResult("KEEP_WAITING")); // nie my, ale warto dalej próbować } } } } }