public SmartChartDto GetSmartChartById(int smartChartId) { var response = new SmartChartDto(); try { var smartChartRepository = new SmartChartRepository(); var smartChart = smartChartRepository.Query().FirstOrDefault(x => x.idSmartChart == smartChartId); if (smartChart != null) { response = new SmartChartDto() { idSmartReport = smartChart.idSmartReport, SmartReport = new SmartReportDto() { idServiceDelivery = smartChart.SmartReport.idServiceDelivery, }, ChartName = smartChart.ChartName }; } smartChartRepository.Dispose(); } catch (Exception ex) { //TODO } return(response); }
public int GetPastDeliveryChart(int smartChartId) { int response = 0; try { var smartChartRepository = new SmartChartRepository(); var deliveryRepository = new ServiceDeliveryRepository(); var smartReportRepository = new SmartReportRepository(); var smartChart = smartChartRepository.Query().FirstOrDefault(x => x.idSmartChart == smartChartId); if (smartChart != null) { var idSubscription = smartChart.SmartReport.ServiceDelivery.ServiceSubscription.idServiceSubscription; var currentDeliveryDate = smartChart.SmartReport.ServiceDelivery.DateDelivered; var currentReportName = smartChart.SmartReport.ReportName; var pastDelivery = deliveryRepository.Query().Where(x => x.IdServiceSubscription == idSubscription && x.DateDelivered < currentDeliveryDate).OrderByDescending(x => x.DateDelivered).FirstOrDefault(); if (pastDelivery != null) { var pastSmartreports = smartReportRepository.Query().Where(x => x.idServiceDelivery == pastDelivery.idServiceDelivery).ToList(); if (pastSmartreports != null) { foreach (var smartReport in pastSmartreports) { if (smartReport.ReportName.Equals(currentReportName)) { var pastChart = smartChartRepository.Query().FirstOrDefault(x => x.idSmartReport == smartReport.idSmartReport && x.IdChartType == smartChart.IdChartType && x.ChartName.Contains(smartChart.ChartName)); if (pastChart != null && smartChartId != pastChart.idSmartChart) { response = pastChart.idSmartChart; } } } } } } } catch (Exception ex) { //TODO return(0); } return(response); }
//private static readonly Logger _log = LogManager.GetCurrentClassLogger(); public SmartChartResponse GetChartsBySmartReportId(int smartReportId) { var response = new SmartChartResponse(); try { var smartChartRepository = new SmartChartRepository(); var smartReportRepository = new SmartReportRepository(); var chartCommentsRepository = new ChartCommentRepository(); var smartReport = smartReportRepository.Query().FirstOrDefault(x => x.idSmartReport == smartReportId); if (smartReport != null) { response.Delivery = new ServiceDeliveryDto() { DateDelivered = smartReport.ServiceDelivery.DateDelivered, DeliveryDateTo = smartReport.ServiceDelivery.DeliveryDateTo }; response.SmartReport = new SmartReportDto() { ReportName = smartReport.ReportName, Insights = smartReport.Insights }; var smartCharts = smartChartRepository.Query() .Where(x => x.idSmartReport == smartReportId && x.ChartType.idChartType != 10) .OrderBy(x => x.ChartOrder) .ToList(); foreach (var smartChart in smartCharts) { response.SmartCharts.Add(new SmartChartDto() { idSmartChart = smartChart.idSmartChart, IdChartType = smartChart.IdChartType, ChartType = null, Insights = smartChart.Insights, CssClasses = smartChart.CssClasses, ChartName = smartChart.ChartName, ChartTypeName = smartChart.ChartType.ChartTypeName, ChartOrder = smartChart.ChartOrder, CommentsCount = chartCommentsRepository.Query().Where(x => x.IdSmartChart == smartChart.idSmartChart && x.IsActive == true).Count() }); } smartChartRepository.Dispose(); smartReportRepository.Dispose(); response.Acknowledgment = true; response.Message = "Success"; } } catch (Exception ex) { response.Acknowledgment = false; response.Message = "Error getting SmartCharts. Exception :" + ex.Message; } return(response); }
public List <int> GetChartsIdByDateRange(int currentChartId, string chartName, string dateFrom, string dateTo) { var response = new List <int>(); try { var serviceDeliveryRepository = new ServiceDeliveryRepository(); var smartChartRepository = new SmartChartRepository(); //_log.Warn("Started"); var from = DateTime.Parse(dateFrom).AddDays(1); var to = DateTime.Parse(dateTo); var report = smartChartRepository.Query().FirstOrDefault(x => x.idSmartChart == currentChartId).SmartReport; var deliveries = serviceDeliveryRepository.Query().Where(x => x.IdServiceSubscription == report.ServiceDelivery.IdServiceSubscription && x.DateDelivered <from && x.DateDelivered> to).ToList(); var currentReportName = report.ReportName; foreach (var delivery in deliveries) { foreach (var smartReport in delivery.SmartReports) { if (smartReport.ReportName.Equals(currentReportName)) { foreach (var smartChart in smartReport.SmartCharts) { if (smartChart.ChartName.Equals(chartName) && currentChartId != smartChart.idSmartChart && smartChart.ChartType.idChartType != 10) { response.Add(smartChart.idSmartChart); } } } } } response.Add(currentChartId); serviceDeliveryRepository.Dispose(); smartChartRepository.Dispose(); } catch (Exception ex) { } return(response); }