Exemplo n.º 1
0
        public IActionResult Put([FromBody] TeilnehmerViewModel model)
        {
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            // handle the insert (without object-mapping)
            var teilnehmer = new Teilnehmer();

            // properties taken from the request
            teilnehmer.GruppenId      = model.GruppenId;
            teilnehmer.Vorname        = model.Vorname;
            teilnehmer.Nachname       = model.Nachname;
            teilnehmer.Berechtigungen = model.Berechtigungen;
            // properties set from server-side
            teilnehmer.CreatedDate      = DateTime.Now;
            teilnehmer.LastModifiedDate = teilnehmer.CreatedDate;
            // add the new quiz
            DbContext.Teilnehmer.Add(teilnehmer);
            // persist the changes into the Database.
            DbContext.SaveChanges();
            // return the newly-created Quiz to the client.
            return(new JsonResult(teilnehmer.Adapt <CodeAktivitaetenViewModel>(),
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }
Exemplo n.º 2
0
        public void ShowWindow(BaseViewModel viewModel, bool showAsDialog = false)
        {
            Window window = viewModel switch
            {
                // Wenn viewModel null ist -> ArgumentNullException
                null => throw new ArgumentNullException(nameof(viewModel)),

                      MainViewModel _ => new MainWindow(),
                      TeilnehmerViewModel _ => new TeilnehmerWindow(),

                      // default -> InvalidOperationException
                      _ => throw new InvalidOperationException($"Unbekanntes ViewModel '{viewModel}'"),
            };

            _windows[viewModel] = window;

            window.DataContext = viewModel;

            if (showAsDialog)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
        }
Exemplo n.º 3
0
        public IActionResult Post([FromBody] TeilnehmerViewModel model)
        {
            // return a generic HTTP Status 500 (Server Error)
            // if the client payload is invalid.
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            // Aktivität holen
            var teilnehmer = DbContext.Teilnehmer.Where(q => q.Id == model.Id).FirstOrDefault();

            // handle requests asking for non-existing quizzes
            if (teilnehmer == null)
            {
                return(NotFound(new
                {
                    Error = String.Format("Aktivität ID {0} nicht gefunden.", model.Id)
                }));
            }

            // handle the update (without object-mapping)
            // by manually assigning the properties
            // we want to accept from the request
            teilnehmer.GruppenId      = model.GruppenId;
            teilnehmer.Vorname        = model.Vorname;
            teilnehmer.Nachname       = model.Nachname;
            teilnehmer.Berechtigungen = model.Berechtigungen;
            // properties set from server-side
            teilnehmer.LastModifiedDate = teilnehmer.CreatedDate;

            // persist the changes into the Database.
            DbContext.SaveChanges();

            // return the updated Quiz to the client.
            return(new JsonResult(teilnehmer.Adapt <TeilnehmerViewModel>(),
                                  new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            }));
        }