示例#1
0
        public ActionResult EditAuthor(AuthorsEditAuthorVM model)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            AuthorsRepository authorsRepository    = new AuthorsRepository(context);

            Author author = null;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                if (model.ID > 0)
                {
                    author = authorsRepository.GetByID(model.ID);
                }
                else
                {
                    author = new Author();
                }

                author.ID        = model.ID;
                author.FirstName = model.FirstName;
                author.LastName  = model.LastName;

                authorsRepository.Save(author);
            }

            return(RedirectToAction("Index", "Authors"));
        }
示例#2
0
        public ActionResult EditAuthor(int id)
        {
            LibraryManagementSystemContext context = new LibraryManagementSystemContext();
            AuthorsRepository   authorsRepository  = new AuthorsRepository(context);
            AuthorsEditAuthorVM model = new AuthorsEditAuthorVM();

            Author author = authorsRepository.GetByID(id);

            if (id > 0)
            {
                if (author == null)
                {
                    return(RedirectToAction("Index", "Authors"));
                }

                model.ID        = author.ID;
                model.FirstName = author.FirstName;
                model.LastName  = author.LastName;
            }

            return(View(model));
        }