Esempio n. 1
0
        public bool InitializeMesLevel()
        {
            var context = GetContext();

            context.ActualPage = enPage.Mes;

            if (context.User.Role == enRole.Administrator)
            {
                context.AllPlants = _mesService.GetAllPlantsMachines();
            }
            else if (context.User.Role == enRole.Demo)
            {
                context.AllPlants = _mesService.GetAllPlantsRole(enRole.Demo);
            }
            else if (context.User.Role == enRole.Assistance || context.User.Role == enRole.RandD)
            {
                if (context.AssistanceUserId != null)
                {
                    context.AllPlants = _assistanceService.GetCustomerPlants(new Guid(context.AssistanceUserId));
                }
                else if (context.AssistanceMachineId != null)
                {
                    context.AllPlants = new List <PlantModel>()
                    {
                        _mesService.GetMachinePlant(context.AssistanceMachineId)
                    };
                }
            }
            else
            {
                context.AllPlants = _mesService.GetUserPlants(context.User.ID);
            }


            context.ActualPeriod = new PeriodModel()
            {
                LastUpdate = new DataUpdateModel()
                {
                    DateTime = DateTime.UtcNow,
                    TimeZone = context.User.TimeZone
                }
            };

            if (context.AllPlants.Any())
            {
                if (context.ActualPlant == null || context.AllPlants.FirstOrDefault(p => p != null && p.Id == context.ActualPlant.Id) == null)
                {
                    context.ActualPlant = context.AllPlants.FirstOrDefault();
                }

                if (context.User.Role == enRole.Administrator)
                {
                    context.AllMachines = _machineService.GetAllMachines();
                }
                else if (context.User.Role == enRole.Demo)
                {
                    context.AllMachines = _machineService.GetRoleMachines(enRole.Demo);
                }
                else if (context.User.Role == enRole.Assistance || context.User.Role == enRole.RandD)
                {
                    if (context.AssistanceUserId != null)
                    {
                        context.AllMachines = _machineService.GetUserMachines(context);
                    }
                    else if (context.AssistanceMachineId != null)
                    {
                        context.AllMachines = _machineService.GetPlantMachines(context);
                    }
                }
                else
                {
                    context.AllMachines = _machineService.GetUserMachines(context);
                }

                SetContext(context);
            }

            return(true);
        }