示例#1
0
        public IEnumerable <IEvent <ProjectTimeAggregateRoot, int> > Execute(CancelInvoiceCommand command)
        {
            CheckUserBillingRights(command.ProjectId, command.ByUserId);

            var userInvoices = State.Invoices.Where(i => i.InvoiceNum == command.InvoiceNum);

            if (!userInvoices.Any())
            {
                throw new ArgumentException("Invoice number is not valid: invoice either cancelled or not exists.");
            }

            var events = userInvoices.Select(ui => new InvoiceEvent
            {
                At                 = DateTimeOffset.Now,
                EventType          = InvoiceEventType.Cancel,
                Hours              = ui.Hours,
                InvoiceNum         = ui.InvoiceNum,
                InvoiceSum         = ui.Sum,
                ProjectId          = command.ProjectId,
                UserId             = ui.UserId,
                RegisteredAt       = DateTimeOffset.Now,
                RegisteredByUserId = command.ByUserId
            });

            return(events);
        }
        public void CancelInvoice(int projectId, string invoiceNum)
        {
            if (String.IsNullOrWhiteSpace(invoiceNum))
            {
                throw new ArgumentNullException("invoiceNum");
            }

            var command = new CancelInvoiceCommand
            {
                ByUserId   = _currentUser.Id,
                InvoiceNum = invoiceNum,
                ProjectId  = projectId
            };

            _cqrs.Execute(command);
        }