public IHttpActionResult NewReservation(Int32 eventID, Int32 seatNumber) { BaseViewModel viewmodel = new BaseViewModel(); SeatDataController dataCtrl = new SeatDataController(); try { SeatingViewModelItem seat = new SeatingViewModelItem().FromModel(dataCtrl.GetItem(seatNumber, eventID)); if (seat.ReservationState == 0) { Seat item = new Seat() { EventID = eventID, ReservationDate = DateTime.Now, UserID = UserHelper.CurrentUserID, SeatNumber = seatNumber, IsActive = true, Payed = false, State = 1, Description = "" }; dataCtrl.Insert(item); } else if (seat.ReservationState < 0) { return(Warning(viewmodel, "Dieser Platz ist gesperrt und kann nicht reserviert werden.")); } else { return(Warning(viewmodel, $"Dieser Platz wurde bereits von {seat.User.Nickname} reserviert.")); } } catch (Exception ex) { return(Error(viewmodel, ex)); } return(Ok(viewmodel, "Platz wurde reserviert.")); }
public IHttpActionResult Backend_Detail_Update(Int32 EventID, Int32 SeatNumber, BackendSeatingViewModelItem request) { BackendSeatingViewModel viewmodel = new BackendSeatingViewModel(); SeatDataController dataCtrl = new SeatDataController(); try { var seats = dataCtrl.GetItems().Where(x => x.EventID == EventID); Seat model = seats.FirstOrDefault(x => x.SeatNumber == SeatNumber); Seat result = null; if (request.ReservationState.Key != 0) { if (model == null) { result = dataCtrl.Insert(request.ToModel()); } else { result = request.ToModel(); result.ID = model.ID; result = dataCtrl.Update(result); } viewmodel.Data.FromModel(result); } else { if (model != null) { dataCtrl.Delete(model.ID); } } } catch (Exception ex) { return(Error(viewmodel, ex)); } return(Ok(viewmodel, "Sitzplatz gespeichert.")); }