public async Task <AggregateDto> ExploreAsync(IAggregateRootId id) { EventStream stream = await eventStore.LoadAsync(id).ConfigureAwait(false); if (stream.Commits.Count() == 0) { return(new AggregateDto()); } var commitsDto = stream.Commits.Select(commit => new AggregateCommitDto() { AggregateRootRevision = commit.Revision, Events = commit.Events.Select(x => new EventDto() { EventName = x.GetType().Name, EventData = x }).ToList(), Timestamp = DateTime.FromFileTimeUtc(commit.Timestamp) }).ToList(); var arDto = new AggregateDto() { BoundedContext = boundedContext.Name, AggregateId = id.Value, Commits = commitsDto }; return(arDto); }
public async Task <IActionResult> GetAggregate([FromQuery] DateFiter dateFiter) { var ShipmentTotal = this._context.Orders.AsQueryable(); var TotalIncome = this._context.Incomes.AsQueryable(); var TotalOutCome = this._context.OutComes.AsQueryable(); if (dateFiter.FromDate != null) { ShipmentTotal = ShipmentTotal.Where(c => c.Date >= dateFiter.FromDate); TotalIncome = TotalIncome.Where(c => c.Date >= dateFiter.FromDate); TotalOutCome = TotalOutCome.Where(c => c.Date >= dateFiter.FromDate); } if (dateFiter.ToDate != null) { ShipmentTotal = ShipmentTotal.Where(c => c.Date <= dateFiter.ToDate); TotalIncome = TotalIncome.Where(c => c.Date <= dateFiter.ToDate); TotalOutCome = TotalOutCome.Where(c => c.Date <= dateFiter.ToDate); } ShipmentTotal = ShipmentTotal.Where(c => c.OrderStateId == (int)OrderStateEnum.Finished && c.OrderplacedId != (int)OrderplacedEnum.CompletelyReturned); AggregateDto aggregateDto = new AggregateDto() { ShipmentTotal = await ShipmentTotal.SumAsync(c => c.DeliveryCost - c.AgentCost), TotalIncome = await TotalIncome.SumAsync(c => c.Earining), TotalOutCome = await TotalOutCome.SumAsync(c => c.Amount) }; return(Ok(aggregateDto)); }
public async Task <IActionResult> Explore([FromQuery] RequestModel model) { AggregateDto result = new AggregateDto(); try { result = await _eventExplorer.ExploreAsync(AggregateUrn.Parse(model.Id, Urn.Uber)); } catch (Exception ex) { logger.ErrorException(ex, () => $"Failed to explore aggregate for {model.Id}"); } return(new OkObjectResult(new ResponseResult <AggregateDto>(result))); }
public AggregateDto AggregateRead(int ID) { var result = new AggregateDto(); try { using (var db = new ONRRDatabaseEntities()) { var query = db.ONRRAggregateSelect(ID); result = Mapper.Map <AggregateDto>(query.FirstOrDefault()); } return(result); } catch (Exception ex) { log.Error(ex.Message + Environment.NewLine + ex.StackTrace); throw; } }