public HttpError Process(Request request) { var entityType = (EntityType)Enum.Parse(typeof(EntityType), (string)request.Query[_typeParameter]); var entityId = EntityUtils.GetEntityId((string)request.Query[Parameter], entityType); return(InvoiceUtils.ActiveInvoiceExists(_user, entityId, entityType) ? new HttpError(HttpStatusCode.Forbidden, $"Invoice for same {entityType.ToString()} already exists") : null); }
public void ProcessConfirmedInvoice_DataCorrect_InvoiceProcessed() { var user = UserFaker.Create(); var balance = UserBalanceRepository.FindOrCreate(user, CurrencyType.BitCoin); var invoice = InvoiceFaker.Create(user, balance.id, EntityType.UserBalance); invoice = invoice.UpdateStatus(InvoiceStatus.Confirmed).Refresh(); invoice = InvoiceUtils.ProcessConfirmedInvoice(invoice).Refresh(); balance = balance.Refresh(); Assert.NotNull(balance); Assert.AreEqual(InvoiceStatus.Done, invoice.status); Assert.AreEqual(invoice.amount, balance.balance); }
protected override void Merge(Invoice source, Invoice target) { InvoiceUtils.Merge(source, target); }
protected override QueryFilters <InvoiceProperty> GetChanges(Invoice original, Invoice changed) { return(InvoiceUtils.GetChanges(original, changed)); }
public CliResult Execute() { Output("Approving invoice"); Output("Type invoice id:"); var id = Convert.ToInt32(Console.ReadLine()); var invoice = Invoice.Find(id); if (invoice == null) { Output($"Invoice with id {id} not found"); return(new CliResult(CliExitCode.NotFound, StrOutput)); } Output("Invoice:"); Output(JObject.FromObject(invoice).ToString()); Output("Transformed invoice:"); Output(new InvoiceTransformer().Transform(invoice).ToString()); Output("Invoice user:"******"Invoice has invalid status - allowed only: " + InvoiceStatus.RequiresConfirmation); return(new CliResult(CliExitCode.UnknownError, StrOutput)); } var isApproving = Ask("Approve that invoice?"); if (!isApproving) { Output("Aborted."); return(new CliResult(CliExitCode.Ok, StrOutput)); } Output("Approving invoice..."); invoice = InvoiceUtils.ConfirmInvoice(invoice); var isProcessing = Ask("Process confirmed invoice?"); if (!isProcessing) { return(new CliResult(CliExitCode.Ok, StrOutput)); } var balance = UserBalanceRepository.Find(invoice.User()); Output("Balance before:"); Output(new UserBalanceTransformer().Transform(balance).ToString()); Output("Processing invoice..."); invoice = InvoiceUtils.ProcessConfirmedInvoice(invoice); Output("Invoice processing finished..."); Output("Balance after:"); Output(new UserBalanceTransformer().Transform(balance.Refresh()).ToString()); Output("Transformed invoice:"); Output(new InvoiceTransformer().Transform(invoice).ToString()); return(new CliResult(CliExitCode.Ok, StrOutput)); }