Esempio n. 1
0
        public ActionResult Grid(GridParams gridParams)
        {
            var templates = HighlightOrderService.GetHighlights(new GetHighlightOrdersRequest
            {
                Skip = gridParams.DisplayStart,
                Take = gridParams.DisplayLength,
                SortingDictionary = gridParams.SortingDictionary,
                Search            = gridParams.Search
            });

            var data = new
            {
                sEcho                = gridParams.Echo + 1,
                iTotalRecords        = templates.HighlightOrders.Count,
                iTotalDisplayRecords = templates.TotalRecords,
                aaData               = templates.HighlightOrders
            };

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Display()
        {
            //var nlsList = _nlsService.GetNLSList(new GetNLSListRequest { TheActiveOnes = true });
            var vesselSchedules = _vesselScheduleService.GetVesselSchedules(new GetVesselSchedulesRequest
            {
                allActiveList = true,
                Skip = 0,
                Take = 20,
            });
            var viewModel = new DailyExecutionReportViewModel();
            viewModel.CurrentUserRoleId = UserProfile().RoleId;
             var staticHighlightsResp = _highlightOrderService.GetStaticHighlights(new GetStaticHighlightOrdersRequest { Take = -1 });
             viewModel.IsAuthorizedToManageAlert = staticHighlightsResp.HighlightOrders.First(x => x.Name == "Weather").RoleGroupIds.Contains(viewModel.CurrentUserRoleId);
             viewModel.IsAuthorizedToManageVesselSchedule = staticHighlightsResp.HighlightOrders.First(x => x.Name == "Vessel Schedule").RoleGroupIds.Contains(viewModel.CurrentUserRoleId);
             viewModel.IsAuthorizedToManageAlert = staticHighlightsResp.HighlightOrders.First(x => x.Name == "Alert").RoleGroupIds.Contains(viewModel.CurrentUserRoleId);
            var periodeTypeQS = !string.IsNullOrEmpty(Request.QueryString["PeriodeType"]) ? Request.QueryString["PeriodeType"].ToLower() : "daily";
            var periodeQS = !string.IsNullOrEmpty(Request.QueryString["Periode"]) ? Request.QueryString["Periode"] : null;
            switch (periodeTypeQS)
            {
                case "monthly":
                    viewModel.PeriodeType = PeriodeType.Monthly;
                    if (!string.IsNullOrEmpty(periodeQS))
                    {
                        viewModel.Periode = DateTime.ParseExact("01/" + periodeQS, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        if (viewModel.Periode.Value.Month == DateTime.Now.Month
                       && viewModel.Periode.Value.Year == DateTime.Now.Year)
                        {
                            viewModel.Periode = null;
                        }
                    }

                    break;
                case "yearly":
                    viewModel.PeriodeType = PeriodeType.Yearly;
                    if (!string.IsNullOrEmpty(periodeQS))
                    {
                        viewModel.Periode = DateTime.ParseExact("01/01/" + periodeQS, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        if (viewModel.Periode.Value.Year == DateTime.Now.Year)
                        {
                            viewModel.Periode = null;
                        }
                    }

                    break;
                default:
                    viewModel.PeriodeType = PeriodeType.Daily;
                    if (!string.IsNullOrEmpty(periodeQS))
                    {
                        viewModel.Periode = DateTime.ParseExact(periodeQS, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        if (viewModel.Periode.Value.Day == DateTime.Now.Day
                        && viewModel.Periode.Value.Month == DateTime.Now.Month
                        && viewModel.Periode.Value.Year == DateTime.Now.Year)
                        {
                            viewModel.Periode = null;
                        }
                    }

                    break;
            }

            viewModel.NLSList = vesselSchedules.VesselSchedules.MapTo<DailyExecutionReportViewModel.NLSViewModel>();
            viewModel.Weather = _waetherService.GetWeather(new GetWeatherRequest { Date = viewModel.Periode, ByDate = true }).MapTo<DailyExecutionReportViewModel.WeatherViewModel>();

            viewModel.HighlightGroupTemplates = _highlightGroupService.GetHighlightGroups(new GetHighlightGroupsRequest
            {
                Take = -1,
                SortingDictionary = new Dictionary<string, SortOrder> { { "Order", SortOrder.Ascending } },
                OnlyIsActive = true
            }).HighlightGroups.MapTo<DailyExecutionReportViewModel.HighlightGroupViewModel>();
            var dynamicHighlights = _highlightService.GetDynamicHighlights(new GetDynamicHighlightsRequest
            {
                PeriodeType = viewModel.PeriodeType,
                Periode = viewModel.Periode
            });
            viewModel.HighlightGroups = dynamicHighlights.HighlightGroups.MapTo<DailyExecutionReportViewModel.HighlightGroupViewModel>();

            //viewModel.Highlights = _highlightService.GetHighlights(new GetHighlightsRequest { Except = new string[1] { "Alert"}, Date = DateTime.Now.Date, IsActive = true }).Highlights.MapTo<DailyExecutionReportViewModel.HighlightViewModel>();
            //viewModel.PlantOperations = _highlightService.GetHighlights(new GetHighlightsRequest { Include = new string[4] { "Process Train", "Storage And Loading", "Utility", "Upstream" }, Date = DateTime.Now.Date, IsActive = true }).Highlights.MapTo<DailyExecutionReportViewModel.HighlightViewModel>();
            viewModel.Alert = _highlightService.GetHighlight(new GetHighlightRequest { Type = "Alert", Date = viewModel.Periode }).MapTo<DailyExecutionReportViewModel.AlertViewModel>();
            if (viewModel.Alert.TypeId == 0) {
                viewModel.Alert.TypeId = _selectService.GetSelect(new GetSelectRequest { Name = "Alert" }).Id;
            }
            var highlightOrders = _highlightOrderService.GetHighlights(new GetHighlightOrdersRequest { Take = -1, SortingDictionary = new Dictionary<string, SortOrder> { { "Order", SortOrder.Ascending } } });
            foreach (var highlight in highlightOrders.HighlightOrders)
            {
                var highlightVM = viewModel.Highlights.FirstOrDefault(x => x.Type == highlight.Value);
                if (highlightVM != null)
                {
                    highlightVM.Order = highlight.Order;
                }
            }
            viewModel.Highlights = viewModel.Highlights.OrderBy(x => x.Order).ToList();
            if (!viewModel.Periode.HasValue)
            {
                viewModel.Periode = dynamicHighlights.Periode;
            }
            return View(viewModel);
        }