public ServiceDeliveryResponse GetServiceSDeliveryById(int serviceDeliveryId)
        {
            var response = new ServiceDeliveryResponse();

            try
            {
                var serviceDeliveryRepository = new ServiceDeliveryRepository();
                var serviceDelivery           = serviceDeliveryRepository.Query().FirstOrDefault(x => x.idServiceDelivery == serviceDeliveryId);
                if (serviceDelivery != null)
                {
                    response.ServiceDelivery = new ServiceDeliveryDto()
                    {
                        idServiceDelivery     = serviceDelivery.idServiceDelivery,
                        IdServiceSubscription = serviceDelivery.IdServiceSubscription,
                        DateDelivered         = serviceDelivery.DateDelivered,
                        DeliveryDateTo        = serviceDelivery.DeliveryDateTo
                    };
                    response.Acknowledgment = true;
                    response.Message        = "Success";
                }
                else
                {
                    response.Acknowledgment = false;
                    response.Message        = "Invalid Delivery Id";
                }
            }
            catch (Exception ex)
            {
                response.Acknowledgment = false;
                response.Message        = ex.Message;
            }

            return(response);
        }
        public BaseResponse AddServiceDelivery(DateTime dateDelivered, DateTime deliveryDateTo, int idServiceSubscription)
        {
            var response = new BaseResponse();

            try
            {
                var serviceDeliveryRepository = new ServiceDeliveryRepository();
                serviceDeliveryRepository.Add(new ServiceDelivery()
                {
                    DateDelivered         = dateDelivered,
                    DeliveryDateTo        = deliveryDateTo,
                    IdServiceSubscription = idServiceSubscription
                });
                serviceDeliveryRepository.SaveChanges();
                response.Acknowledgment = true;
                response.Message        = "Success";
            }
            catch (Exception ex)
            {
                response.Acknowledgment = false;
                response.Message        = ex.Message;
            }

            return(response);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }