Beispiel #1
0
        // GET: OptGroup
        public ActionResult Create()
        {
            OptGroupViewModel objEntity = new OptGroupViewModel();
            var objProjectEntity        = new List <OptGroupViewModel>();
            var objProjectList          = new List <SelectListItem>();

            objProjectList.Add(new SelectListItem {
                Text = "Select", Value = "",
            });
            OptGroupRepository objStateRepository = new OptGroupRepository();

            objProjectEntity = objStateRepository.OptGroupSelect(StudentFlags.OptDroupStudent.GetHashCode());
            foreach (var item in objProjectEntity)
            {
                objProjectList.Add(new SelectListItem {
                    Text = item.StateName, Value = Convert.ToString(item.StateId), Group = new SelectListGroup {
                        Name = item.CountryName
                    }
                });
            }
            objEntity.SelectCountryList = new SelectList(objProjectEntity, "StateId", "StateName", "CountryName", 1);                //new SelectList(objTaskList);
            objEntity.StateList         = objProjectEntity;

            return(View(objEntity));
        }
        public List <OptGroupViewModel> OptGroupSelect(int flag)
        {
            var objEntityList = new List <OptGroupViewModel>();

            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SP_StateOptionSelectViewModelSelect))
                {
                    objDB.AddInParameter(sprocCmd, PARAM_Flag, DbType.Int32, flag);


                    using (IDataReader reader = objDB.ExecuteReader(sprocCmd))
                    {
                        while (reader.Read())
                        {
                            var objEntityViewModel = new OptGroupViewModel();


                            objEntityViewModel.CountryId   = reader.GetColumnValue <int>(PARAM_CountryId);
                            objEntityViewModel.CountryName = reader.GetColumnValue <string>(PARAM_CountryName);
                            objEntityViewModel.StateId     = reader.GetColumnValue <int>(PARAM_StateId);
                            objEntityViewModel.StateName   = reader.GetColumnValue <string>(PARAM_Name);



                            if (objEntityViewModel != null)
                            {
                                objEntityList.Add(objEntityViewModel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return(objEntityList);
        }