示例#1
0
        public Book(Guid id, string title, string isbn, IBookUniquenessChecker uniquenessChecker)
            : this(id)
        {
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ApplicationException("Title is required");
            }
            if (string.IsNullOrWhiteSpace(isbn))
            {
                throw new ApplicationException("ISBN is required");
            }
            if (uniquenessChecker.IsTitleExist(title))
            {
                throw new ApplicationException("Title is already exist");
            }
            if (uniquenessChecker.IsISBNExist(isbn))
            {
                throw new ApplicationException("ISBN is already exist");
            }

            title = title.Trim();
            isbn  = isbn.Trim();
            RaiseEvent(new BookRegistered {
                Id = id, Title = title, ISBN = isbn
            });
        }
示例#2
0
        public void Correct(string title, IBookUniquenessChecker uniquenessChecker)
        {
            if (string.IsNullOrWhiteSpace(title)) throw new ApplicationException("Title is required");
            if (deleted) throw new ApplicationException("This book has already deleted");

            title = title.Trim();
            if (this.title != title)
            {
                if (uniquenessChecker.IsTitleExist(title)) throw new ApplicationException("Title is already exist");
                RaiseEvent(new BookCorrected { Id = Id, Title = title });
            }
        }
示例#3
0
        public Book(Guid id, string title, string isbn, IBookUniquenessChecker uniquenessChecker)
            : this(id)
        {
            if (string.IsNullOrWhiteSpace(title)) throw new ApplicationException("Title is required");
            if (string.IsNullOrWhiteSpace(isbn)) throw new ApplicationException("ISBN is required");
            if (uniquenessChecker.IsTitleExist(title)) throw new ApplicationException("Title is already exist");
            if (uniquenessChecker.IsISBNExist(isbn)) throw new ApplicationException("ISBN is already exist");

            title = title.Trim();
            isbn = isbn.Trim();
            RaiseEvent(new BookRegistered { Id = id, Title = title, ISBN = isbn });
        }
示例#4
0
        public void Correct(string title, IBookUniquenessChecker uniquenessChecker)
        {
            if (string.IsNullOrWhiteSpace(title))
            {
                throw new ApplicationException("Title is required");
            }
            if (deleted)
            {
                throw new ApplicationException("This book has already deleted");
            }

            title = title.Trim();
            if (this.title != title)
            {
                if (uniquenessChecker.IsTitleExist(title))
                {
                    throw new ApplicationException("Title is already exist");
                }
                RaiseEvent(new BookCorrected {
                    Id = Id, Title = title
                });
            }
        }
 public BookCommandHandler(IRepository repo, IBookUniquenessChecker uniquenessChecker)
     : base(repo)
 {
     this.uniquenessChecker = uniquenessChecker;
 }