public async Task <ChartLayoutModel> GetDefaultLayoutAsync(QuotePeriod period) { var result = new ChartLayoutModel(); using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IChartLayoutRepository>(); var layout = await repository.GetDefaultAsync(period); if (layout == null) { return(result); } result.LayoutId = layout.LayoutId; result.Deleted = layout.Deleted; result.Title = layout.Title; //result.Period = layout.Period; result.Default = layout.Default; result.Description = layout.Description; result.Plots = await GetChartPlotsForLayout(scope, result.LayoutId); } return(result); }
public async Task <IHttpActionResult> SaveLayout([FromBody] ChartLayoutModel model) { await _service.SaveLayoutAsync(model); return(Ok(model)); }
public async Task SaveLayoutAsync(ChartLayoutModel model) { using (var scope = _container.BeginLifetimeScope()) { var repository = scope.Resolve <IChartLayoutRepository>(); IChartLayoutEntity layout = null; if (model.LayoutId > 0) { layout = await repository.GetAsync(model.LayoutId); } else { layout = repository.Add(new ChartLayout()); } if (layout != null) { layout.Title = model.Title; layout.Description = model.Description; //layout.Period = model.Period; repository.Commit(); if (model.LayoutId == 0) { model.LayoutId = layout.LayoutId; } if (model.Plots.Any()) { var plotRepository = scope.Resolve <IChartPlotRepository>(); var indicatorRepository = scope.Resolve <IChartIndicatorRepository>(); foreach (var plot in model.Plots) { var entity = await plotRepository.GetAsync(plot.PlotId) ?? plotRepository.Add(new ChartPlot { LayoutId = plot.LayoutId, }); entity.OrderId = model.Plots.IndexOf(plot); entity.Height = plot.Height; plotRepository.Commit(); if (plot.PlotId == 0) { plot.PlotId = entity.PlotId; } foreach (var indicator in plot.Indicators) { var record = await indicatorRepository.GetAsync(indicator.PlotId, indicator.IndicatorId) ?? indicatorRepository.Add(new ChartIndicator { IndicatorId = indicator.IndicatorId, PlotId = indicator.PlotId }); record.OrderId = plot.Indicators.IndexOf(indicator); record.LineColor = indicator.LineColor; indicatorRepository.Commit(); if (indicator.Id == 0) { indicator.Id = record.Id; } } } } } } }