Exemple #1
0
        private WasteViewModel InitIndexViewModel(WasteViewModel model)
        {
            var company   = GlobalFunctions.GetCompanyList(_companyBll);
            var listPlant = GlobalFunctions.GetPlantAll();

            if (CurrentUser.UserRole != Enums.UserRole.Administrator)
            {
                var userPlantCompany = _userPlantMapBll.GetCompanyByUserId(CurrentUser.USER_ID);
                var poaMapCompany    = _poaMapBll.GetCompanyByPoaId(CurrentUser.USER_ID);
                var distinctCompany  = company.Where(x => userPlantCompany.Contains(x.Value));
                if (CurrentUser.UserRole == Enums.UserRole.POA)
                {
                    distinctCompany = company.Where(x => poaMapCompany.Contains(x.Value));
                }
                var getCompany = new SelectList(distinctCompany, "Value", "Text");
                company = getCompany;

                var itemPlant = GlobalFunctions.GetPlantAll().Where(x => CurrentUser.ListUserPlants.Contains(x.Value));
                listPlant = new SelectList(itemPlant, "Value", "Text");
            }

            model.CompanyCodeList = company;
            model.PlantWerksList  = listPlant;
            model.MonthList       = GlobalFunctions.GetMonthList(_monthBll);
            model.YearList        = WasteYearList();
            model.Month           = DateTime.Now.Month.ToString();
            model.Year            = DateTime.Now.Year.ToString();

            var input = Mapper.Map <WasteGetByParamInput>(model);

            input.WasteProductionDate = null;
            input.UserId         = CurrentUser.USER_ID;
            input.UserRole       = CurrentUser.UserRole;
            input.ListUserPlants = CurrentUser.ListUserPlants;

            var dbData = _wasteBll.GetAllByParam(input);

            //var dbWasteQty = _wasteBll.CalculateWasteQuantity(dbData);

            model.Details = Mapper.Map <List <WasteDetail> >(dbData);

            return(model);
        }
        private ProductionViewModel InitProductionViewModel(ProductionViewModel model)
        {
            var company = GlobalFunctions.GetCompanyList(_companyBll);

            if (CurrentUser.UserRole != Enums.UserRole.Administrator)
            {
                var userPlantCompany = _userPlantMapBll.GetCompanyByUserId(CurrentUser.USER_ID);
                var poaMapCompany    = _poaMapBll.GetCompanyByPoaId(CurrentUser.USER_ID);
                var distinctCompany  = company.Where(x => userPlantCompany.Contains(x.Value));
                if (CurrentUser.UserRole == Enums.UserRole.POA)
                {
                    distinctCompany = company.Where(x => poaMapCompany.Contains(x.Value));
                }
                company = new SelectList(distinctCompany, "Value", "Text");
            }

            var listPlant = GlobalFunctions.GetPlantAll().Where(x => CurrentUser.ListUserPlants.Contains(x.Value));

            model.CompanyCodeList = company;
            model.PlantWerkList   = new SelectList(listPlant, "Value", "Text");
            model.MonthList       = GlobalFunctions.GetMonthList(_monthBll);
            model.YearList        = ProductionYearList();
            model.Month           = DateTime.Now.Month.ToString();
            model.Year            = DateTime.Now.Year.ToString();

            var input = Mapper.Map <ProductionGetByParamInput>(model);

            input.ProoductionDate = null;
            input.UserRole        = CurrentUser.UserRole;
            input.ListUserPlants  = CurrentUser.ListUserPlants;

            var dbData = _productionBll.GetFactAllByParam(input).OrderByDescending(x => x.PRODUCTION_DATE).ToList();

            model.Details = Mapper.Map <List <ProductionDetail> >(dbData);

            return(model);
        }