Пример #1
0
        public IActionResult AddEditProjectPlan(int?id)
        {
            ProjectPlanViewModel model = new ProjectPlanViewModel();

            try
            {
                var projectPlan = _repository.GetProjectPlanById(id);
                ViewBag.Project  = _repository.GetAllProject();
                ViewBag.WorkType = _repository.GetAllWorkType();
                ViewBag.Person   = _repository.GetAllPerson();
                string[] WorkerListCodesTemp    = new string[0];
                string[] SarparastListCodesTemp = new string[0];
                string[] OstadKarListCodesTemp  = new string[0];
                string   worklistForPass        = string.Empty;
                string   SarparastlistForPass   = string.Empty;
                string   OstadkarlistForPass    = string.Empty;
                if (id.HasValue)
                {
                    if (projectPlan.WorkerListCodes != null)
                    {
                        WorkerListCodesTemp = projectPlan.WorkerListCodes.Split(',');
                        ViewBag.tempq       = WorkerListCodesTemp;
                        worklistForPass     = projectPlan.WorkerListCodes;
                    }
                    if (projectPlan.SarparastCodes != null)
                    {
                        SarparastListCodesTemp = projectPlan.SarparastCodes.Split(',');
                        SarparastlistForPass   = projectPlan.SarparastCodes;
                    }
                    if (projectPlan.OstadKarCodes != null)
                    {
                        OstadKarListCodesTemp = projectPlan.OstadKarCodes.Split(',');
                        OstadkarlistForPass   = projectPlan.OstadKarCodes;
                    }

                    model = _mapper.Map <ProjectPlan, ProjectPlanViewModel>(projectPlan);
                }
                // model.GetPersonList = _repository.GetAllPerson().Select(s => new Person { Id = s.Id, FullName = s.FullName }).ToList();

                List <Person> Lperson;

                Person Tperson;
                //----------worker-----------------
                Lperson = new List <Person>();
                var queryWorker = _repository.GetAllTransitInfo_EnableForCombo_Worker(worklistForPass, "worker");

                // if (id.HasValue)
                // queryWorker = _repository.GetAllTransitInfo_EnableForComboWithoutTime_Worker(worklistForPass,"worker");


                foreach (var item in queryWorker)
                {
                    Tperson          = new Person();
                    Tperson.Id       = item.Id;
                    Tperson.FullName = item.FullName;
                    Lperson.Add(Tperson);
                }

                model.GetWorkerList = Lperson;
                model.workerList    = WorkerListCodesTemp;
                //-------------Sarparast------------
                Lperson = new List <Person>();
                var querySarparast = _repository.GetAllTransitInfo_EnableForCombo_Worker(SarparastlistForPass, "sarparast");

                //  if (id.HasValue)
                //   querySarparast = _repository.GetAllTransitInfo_EnableForComboWithoutTime_Worker(SarparastlistForPass, "sarparast");


                foreach (var item in querySarparast)
                {
                    Tperson          = new Person();
                    Tperson.Id       = item.Id;
                    Tperson.FullName = item.FullName;
                    Lperson.Add(Tperson);
                }

                model.GetSarparastList = Lperson;
                model.sarparastList    = SarparastListCodesTemp;
                //------------Ostadkar---------------
                Lperson = new List <Person>();
                var queryOstadKar = _repository.GetAllTransitInfo_EnableForCombo_Worker(OstadkarlistForPass, "ostadkar");

                // if (id.HasValue)
                //  queryOstadKar = _repository.GetAllTransitInfo_EnableForComboWithoutTime_Worker(OstadkarlistForPass, "ostadkar");


                foreach (var item in queryOstadKar)
                {
                    Tperson          = new Person();
                    Tperson.Id       = item.Id;
                    Tperson.FullName = item.FullName;
                    Lperson.Add(Tperson);
                }

                model.GetOstadKarList = Lperson;
                model.ostadkarList    = OstadKarListCodesTemp;

                // ViewBag.ProcessName = _repository.GetAllControlTools();

                return(PartialView("~/Areas/Transit/Views/Transit/AddEditProjectPlan.cshtml", model));
            }
            catch (Exception ex)
            {
                return(BadRequest("Failed to get orders"));
            }
        }