Esempio n. 1
0
        public async Task <Unit> Handle(AddAnnouncementCommand request, CancellationToken cancellationToken)
        {
            if (_announcementRepository.CountAllByDate(request.PublicationDate, request.UserId).Result >= 5)
            {
                throw new ArgumentException("The number of the same publication date cannot be over than 5.");
            }

            var announcement = new Domain.Announcement(request.Id, request.Title, request.Content, request.PublicationDate, request.UserId);

            await _announcementRepository.AddAsync(announcement);

            await _announcementRepository.SaveChangesAsync();

            return(Unit.Value);
        }