コード例 #1
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var author = personData.GetPersonById(Book.PersonId.Value);
                Book.Author = author;

                if (Book.Id == 0)
                {
                    Book = bookData.Create(Book);
                    TempData["Message"] = "The Object is created!";
                }
                else
                {
                    Book = bookData.Update(Book);
                    TempData["Message"] = "The Object is updated!";
                }

                bookData.Commit();
                return(RedirectToPage("./List"));
            }

            var authors = personData.GetPersons().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" });

            Authors = new SelectList(authors, "Id", "Display");
            return(Page());
        }
コード例 #2
0
        public IActionResult Edit(BookViewModel model)
        {
            if (ModelState.IsValid)
            {
                var author = personData.GetPersonById(model.Book.PersonId.Value);
                model.Book.Author = author;

                if (model.Book.Id == 0)
                {
                    model.Book          = bookData.Create(model.Book);
                    TempData["Message"] = "The Object is created!";
                }
                else
                {
                    model.Book          = bookData.Update(model.Book);
                    TempData["Message"] = "The Object is updated!";
                }

                bookData.Commit();
                return(RedirectToAction("Index"));
            }

            var authors = personData.GetPersons().ToList().Select(p => new { Id = p.Id, Display = $"{p.FirstName} {p.LastName}" });

            model.Authors = new SelectList(authors, "Id", "Display");
            return(View(model));
        }
コード例 #3
0
 public RedirectToActionResult Create(Book b)
 {
     _tracker.Add("Home.Create.Post");
     _bda.Create(b);
     return(RedirectToAction("Index"));
 }