public IActionResult Tobecloned(string grpNo, string productId)
        {
            var grpprdct = _unitofWork.eppGrpprdctRepository.GetEppGrpprdct(grpNo, productId);

            if (grpprdct == null)
            {
                return(NotFound("incorret group number  or product id "));
            }
            EppTemplateViewModel lstEppTemplateViewModel = new EppTemplateViewModel
            {
                AvailableList = new List <EppAttrFieldViewModel>(),
                SelectedList  = new List <EppAttrFieldViewModel>()
            };

            lstEppTemplateViewModel.AvailableList = Helper.EppGetAvailableFields(_unitofWork).ToList();
            lstEppTemplateViewModel.isEdit        = false;

            lstEppTemplateViewModel.AvailableList = Helper.EppGetAvailableFields(_unitofWork).ToList();
            IList <EppAttrFieldViewModel> eppAttrFields = new List <EppAttrFieldViewModel>();

            if (grpprdct != null)
            {
                var eppPrdctattrbt = _unitofWork.eppPrdctattrbtRepository.ClonedEppPrdctattrbts(grpprdct.GrpprdctId);
                foreach (var item in eppPrdctattrbt)
                {
                    var data = _unitofWork.eppAttributeRepository.Get(long.Parse(item.AttrId)).Result;
                    if (data != null)
                    {
                        lstEppTemplateViewModel.SelectedList.Add(new EppAttrFieldViewModel
                        {
                            AttrId       = item.AttrId,
                            DisplyAttrNm = data.DisplyAttrNm,
                            DbAttrNm     = data.DbAttrNm,
                            ClmnOrdr     = item.ClmnOrdr,
                            RqdFlg       = item.RqdFlg,
                        });
                    }
                }
                // removing the item from available list
                foreach (var item in lstEppTemplateViewModel.SelectedList)
                {
                    var isdata = lstEppTemplateViewModel.AvailableList.Where(x => x.DbAttrNm.Contains(item.DbAttrNm)).FirstOrDefault();
                    if (isdata != null)
                    {
                        lstEppTemplateViewModel.AvailableList.Remove(isdata);
                    }
                }
            }

            return(Ok(lstEppTemplateViewModel));
        }
示例#2
0
        public static EppTemplateViewModel GetProductAvailableFields(string webRootPath, IUnitofWork _unitofWork, string groupName)
        {
            string path = Path.Combine(webRootPath, "attrs_maps.json");

            string[] REQUIRED_FPPG = new string[] {
                "emp_hire_dt", "effctv_dt", "grp_nmbr", "emp_sig_dt", "agnt_cd_1",
                "agntsub_1", "agnt_comm_split_1", "owners_lname", "owners_fname",
                "owners_ssn", "owners_addr_ln_1", "owners_addr_city",
                "owners_addr_state", "owners_addr_zip", "emp_plan_cd"
            };

            string[] REQUIRED_ACC_HI = new string[] {
                "grp_nm", "grp_nmbr", "emp_id", "payment_mode", "signd_at_state",
                "agnt_cd_1", "agnt_nm", "owners_fname", "owners_lname",
                "owners_addr_ln_1", "owners_addr_city", "owners_addr_state",
                "owners_addr_zip", "owners_phn", "owners_ssn", "owners_dob",
                "owners_sex"
            };


            string[] REQUIRED_ER_CI = new string[] {
                "emp_hire_dt", "emp_sig_dt", "grp_nmbr", "emp_id", "agnt_cd_1", "agntsub_1",
                "agnt_comm_split_1", "owners_fname", "owners_lname", "owners_addr_ln_1",
                "owners_addr_city", "owners_addr_state", "owners_addr_zip",
                "owners_ssn", "owners_dob", "owners_sex"
            };
            string[] REQUIRED_VOL_CI = new string[] {
                "emp_hire_dt", "enrl_typ", "signd_at_state", "payment_mode", "prduct_cd",
                "effctv_dt", "enrl_typ", "agnt_cd_1", "emp_fname", "emp_lname",
                "emp_addr_ln_1", "emp_addr_city", "emp_addr_state",
                "emp_addr_zip", "emp_ssn", "emp_dob", "emp_gndr", "owners_phn"
            };
            string[] REQUIRED_VGL = new string[] {
                "emp_hire_dt", "enrl_typ", "signd_at_state", "payment_mode", "prduct_cd",
                "effctv_dt", "enrl_typ", "agnt_cd_1", "emp_fname", "emp_lname",
                "emp_addr_ln_1", "emp_addr_city", "emp_addr_state",
                "emp_addr_zip", "emp_ssn", "emp_dob", "emp_gndr", "owners_phn"
            };
            string[] REQUIRED_BGL = new string[] {
                "emp_hire_dt", "enrl_typ", "signd_at_state", "payment_mode", "prduct_cd",
                "effctv_dt", "enrl_typ", "agnt_cd_1", "emp_fname", "emp_lname",
                "emp_addr_ln_1", "emp_addr_city", "emp_addr_state",
                "emp_addr_zip", "emp_ssn", "emp_dob", "emp_gndr", "owners_phn"
            };

            var jsonBytes = File.ReadAllText(path);
            var jsonDoc   = JsonDocument.Parse(jsonBytes);

            var root = jsonDoc.RootElement;
            //var dEppAttrField = new Dictionary<string, List<EppAttrFieldViewModel>>();

            EppTemplateViewModel lstEppTemplateViewModel = new EppTemplateViewModel
            {
                AvailableList = new List <EppAttrFieldViewModel>(),
                SelectedList  = new List <EppAttrFieldViewModel>()
            };

            var listData = EppGetAvailableFields(_unitofWork);

            foreach (var data in listData)
            {
                lstEppTemplateViewModel.AvailableList.Add(data);
            }

            var enumRoot = root.GetProperty(groupName).EnumerateObject();

            foreach (var attrName in enumRoot)
            {
                lstEppTemplateViewModel.SelectedList.Add(new EppAttrFieldViewModel {
                    DbAttrNm = attrName.Value.ToString()
                });
            }

            // mark required field for each product
            switch (groupName)
            {
            case "FPPG":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_FPPG);
                break;

            case "ACC_HI":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_ACC_HI);
                break;

            case "ER_CI":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_ER_CI);
                break;

            case "VOL_CI":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_VOL_CI);
                break;

            case "VGL":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_VGL);
                break;

            case "BGL":
                MarkRequired(lstEppTemplateViewModel.SelectedList, REQUIRED_BGL);
                break;
            }

            foreach (var item in lstEppTemplateViewModel.SelectedList)
            {
                lstEppTemplateViewModel.AvailableList.Remove(lstEppTemplateViewModel.AvailableList.FirstOrDefault(x => x.DbAttrNm.Contains(item.DbAttrNm)));
            }

            return(lstEppTemplateViewModel);
        }