コード例 #1
0
        public ActionResult BookId(Guid id)
        {
            Fail.IfArgumentEmpty(id, nameof(id));

            var book  = BookStore.GetBookById(id);
            var model = new EditBookModel(book);

            return(View("Book", model));
        }
コード例 #2
0
        public ActionResult BookSave([NotNull] EditBookModel model)
        {
            Fail.IfArgumentNull(model, nameof(model));
            Fail.IfArgumentEmpty(model.Id, nameof(model.Id));
            Fail.IfArgumentWhiteSpace(model.Name, nameof(model.Name));

            // TODO: nazwa książki musi być unikalna - wyjątek
            // TODO: Dodaj obsługę wyjątków
            var book      = BookStore.GetBookById(model.Id);
            var duplicate = BookStore.FindBook(model.Name);

            if (duplicate != null && duplicate != book)
            {
                throw new ApplicationException($"There already is book named '{model.Name}'");
            }
            book.Rename(model.Name);
            book.Save();

            return(RedirectToBookEditor(book));
        }