コード例 #1
0
        // GET: DBDrop
        public ActionResult Create()
        {
            var objEntityMap = new DBDropViewModel();

            var objStudentsModelList   = new List <SelectListItem>();
            var objStudentRepository   = new DBDroupRepository();
            var objStudentsModelEntity = new List <DBDropViewModel>();

            objStudentsModelList.Add(new SelectListItem {
                Text = "Select", Value = ""
            });
            objStudentsModelEntity = objStudentRepository.FillDBDrop(StudentFlags.DropStudent.GetHashCode(), new DBDropViewModel());
            foreach (var item in objStudentsModelEntity)
            {
                objStudentsModelList.Add(new SelectListItem {
                    Text = item.Name, Value = Convert.ToString(item.Id)
                });
            }

            objEntityMap.StudentsList = new SelectList(objStudentsModelList, "Value", "Text");



            return(View(objEntityMap));
        }
コード例 #2
0
        public List <DBDropViewModel> FillDBDrop(int Flag, DBDropViewModel objEntity)
        {
            var objEntityList = new List <DBDropViewModel>();

            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_STUDENT_VIEWMODEL_SELECT))
                {
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_FLAG, DbType.Int32, Flag);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_ID, DbType.Int32, objEntity.Id);

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


                            objEntityViewModel.Id   = reader.GetColumnValue <int>(COLUMN_NAME_ID);
                            objEntityViewModel.Name = reader.GetColumnValue <string>(COLUMN_NAME_NAME);



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