public async Task <IActionResult> Calculate([FromBody] CalculateDto calcDto) { var message = _changeService.Calc(calcDto.AmountPaid, calcDto.TotalAmountToPay); if (!_changeService.IsValid) { return(BadRequest(_changeService.GetErrors)); } var historyEntry = new ChangeHistory(_changeService.TotalChanged()); foreach (var(value, quantity) in _changeService.Notes) { var historyEntryItem = new ChangeHistoryItem(ECurrencyType.Note, quantity, value); historyEntry.AddItem(historyEntryItem); } foreach (var(value, quantity) in _changeService.Coins) { var historyEntryItem = new ChangeHistoryItem(ECurrencyType.Coin, quantity, value); historyEntry.AddItem(historyEntryItem); } await _context.ChangeHistories.AddAsync(historyEntry); await _context.SaveChangesAsync(); return(Ok(message)); }
private List <ChangeHistoryItem> ChangeHistory(int id) { List <ChangeHistoryItem> items = new List <ChangeHistoryItem>(); EntityData entityData = new EntityData(); List <EntityDTO> changeHistory = entityData.GetChangeHistory(id); ChangeHistoryComparer comparer = new ChangeHistoryComparer(); changeHistory.Sort(comparer); if (changeHistory.Count > 0) { foreach (EntityDTO related in changeHistory) { ChangeHistoryItem ch = new ChangeHistoryItem(); related.ExtractProperties(); ch.Version = related.RenderHTML(GlobalStringResource.Version, RenderOption.Span); ch.Date = related.RenderHTML(GlobalStringResource.Date, RenderOption.Span); ch.Reason = related.RenderHTML(GlobalStringResource.ReasonforChange, RenderOption.Span); List <EntityDTO> users = entityData.GetRelatedPersons(related.ID); StringBuilder userLinks = new StringBuilder(); if (users.Count > 0) { foreach (EntityDTO user in users) { userLinks.Append(user.RenderAsPopupLink()); userLinks.Append(GlobalStringResource.BreakTag); } } ch.Author = userLinks.ToString(); items.Add(ch); } } return(items); }