public StudentViewModel Edit(int Flag, StudentViewModel objEntity)
        {
            try
            {

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

                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_RESULT, DbType.Int32, objEntity.Result);
                    objDB.ExecuteNonQuery(sprocCmd);
                    objEntity.Result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_RESULT));
                }
                //
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntity;
        }
        public ActionResult Create(StudentViewModel objEntity)
        {
            StudentRepository objStudentRepository = new StudentRepository();

            if (ModelState.IsValid)
            {
                objEntity.Name = objEntity.Name.Trim();

                objEntity = objStudentRepository.Insert(objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    //   Install-Package MvcFlashMessages
                    this.Flash("success", "Student Insert successfully ");

                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("error", "Faild to Insert Student");
                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("warning", "Student Name is Already Exist");
                    return RedirectToAction("Index");
                }
            }
            return View(objEntity);
        }
        public List<StudentViewModel> Select(int Flag, StudentViewModel objEntity)
        {
            var objEntityList = new List<StudentViewModel>();
            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 StudentViewModel();

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

                            if (objEntityViewModel != null)
                            {
                                objEntityList.Add(objEntityViewModel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntityList;
        }
        public List<StudentViewModel> Search(int flag, StudentViewModel entity, int pageIndex, int pageSize, out int totalCount)
        {
            totalCount = 0;
            var objEntityList = new List<StudentViewModel>();
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_STUDENT_VIEWMODEL_SEARCH))
                {

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_PAGEINDEX, DbType.Int32, pageIndex);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_PAGESIZE, DbType.Int32, pageSize);
                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_TOTALCOUNT, DbType.Int32, totalCount);

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

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

                            if (objEntityViewModel != null)
                            {
                                objEntityList.Add(objEntityViewModel);
                            }
                        }
                    }

                    totalCount = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_TOTALCOUNT));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntityList;
        }
        public ActionResult Edit(int id, StudentViewModel objEntity)
        {
            var objStudentRepository = new StudentRepository();

            if (ModelState.IsValid)
            {
                objEntity.Name = objEntity.Name.Trim();

                objEntity.Id = id;

                objEntity = objStudentRepository.Edit(StudentFlags.UpdateByID.GetHashCode(), objEntity);
                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    this.Flash("success", "Student Details updated successfully");
                    return RedirectToAction("Index");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {

                    this.Flash("error", "Student Details failed to Update");
                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {

                    this.Flash("warning", "Student Name is Already Exist");
                }
            }

            return View(objEntity);
        }
        public ActionResult Edit(int id)
        {
            var objStudentRepository = new StudentRepository();
            var objEntity = new StudentViewModel();

            objEntity = objStudentRepository.Select(StudentFlags.SelectByID.GetHashCode(), new StudentViewModel()
            {
                Id = id

            }).FirstOrDefault();
            if (objEntity == null)
            {

                return RedirectToAction("Index");
            }

            return View(objEntity);
        }