コード例 #1
0
        public IHttpActionResult Get(Int32 eventID)
        {
            SeatingListViewModel viewmodel     = new SeatingListViewModel();
            SeatDataController   dataCtrl      = new SeatDataController();
            EventDataController  eventDataCtrl = new EventDataController();

            if (!eventDataCtrl.GetItem(eventID).IsActiveReservation)
            {
                return(Warning(viewmodel, "Die Reservierung ist derzeit deaktiviert."));
            }

            var seats = dataCtrl.GetItems().Where(x => x.EventID == eventID).ToList();

            for (int i = 1; i <= Properties.Settings.Default.SeatAmount; i++)
            {
                SeatingViewModelItem item = new SeatingViewModelItem();
                Seat model = seats.FirstOrDefault(x => x.SeatNumber == i);
                if (model == null)
                {
                    model = new Seat()
                    {
                        SeatNumber = i,
                        State      = 0
                    }
                }
                ;
                item.FromModel(model);
                viewmodel.Data.Add(item);
            }

            return(Ok(viewmodel));
        }
コード例 #2
0
        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."));
        }
コード例 #3
0
        public static SeatingViewModelItem FromModel(this SeatingViewModelItem viewmodel, Seat model)
        {
            viewmodel.ID               = model.ID;
            viewmodel.SeatNumber       = model.SeatNumber;
            viewmodel.ReservationState = model.State;
            viewmodel.ReservationDate  = model.ReservationDate;
            viewmodel.Description      = model.Description;
            viewmodel.IsPayed          = model.Payed;
            viewmodel.User             = null;
            viewmodel.TransferUser     = null;

            if (model.IsActive && model.State != 0 && model.User != null)
            {
                viewmodel.User = new SeatingViewModelItem.SeatingUser()
                {
                    ID        = model.UserID,
                    FirstName = model.User.FirstName,
                    LastName  = model.User.LastName,
                    Nickname  = model.User.Nickname,
                    Email     = model.User.Email
                };
            }

            if (model.IsActive && model.State != 0 && model.TransferUser != null)
            {
                viewmodel.User = new SeatingViewModelItem.SeatingUser()
                {
                    ID        = model.TransferUserID ?? default(int),
                    FirstName = model.TransferUser.FirstName,
                    LastName  = model.TransferUser.LastName,
                    Nickname  = model.TransferUser.Nickname,
                    Email     = model.TransferUser.Email
                };
            }

            return(viewmodel);
        }