Ejemplo n.º 1
0
        public static CateringSeat FromModel(this CateringSeat viewmodel, Seat model)
        {
            viewmodel.ID         = model.ID;
            viewmodel.SeatNumber = model.SeatNumber;

            return(viewmodel);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Get()
        {
            CateringListViewModel         viewmodel     = new CateringListViewModel();
            CateringProductDataController dataCtrl      = new CateringProductDataController();
            SeatDataController            seatDataCtrl  = new SeatDataController();
            EventDataController           eventDataCtrl = new EventDataController();

            try
            {
                var e = eventDataCtrl.GetItems().FirstOrDefault(x => x.Start <= DateTime.Now && x.End >= DateTime.Now);
                if (e == null)
                {
                    return(Warning(viewmodel, "Keine passende Veranstaltung gefunden."));
                }
                else if (!e.IsActiveCatering)
                {
                    return(Warning(viewmodel, "Das Catering ist derzeit deaktiviert."));
                }

                foreach (var model in dataCtrl.GetItems().Where(x => x.IsActive))
                {
                    ProductViewModelItem item = new ProductViewModelItem();

                    item.FromModel(model);
                    viewmodel.Data.Add(item);
                }

                int eventID = e.ID;
                foreach (var model in seatDataCtrl.GetCurrentUserSeats(eventID))
                {
                    CateringSeat item = new CateringSeat();

                    item.FromModel(model);
                    viewmodel.Seats.Add(item);
                }
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel));
        }