public int Delete(int Flag, Student2ViewModel objEntity)
 {
     int result = 0;
     try
     {
         Database objDB = base.GetDatabase();
         // Create a suitable command type and add the required parameter.
         using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_STUDENT2_VIEWMODEL_DELETE))
         {
             objDB.AddInParameter(sprocCmd, COLUMN_NAME_FLAG, DbType.Int32, Flag);
             objDB.AddInParameter(sprocCmd, COLUMN_NAME_STUDENTID, DbType.Int32, objEntity.StudentId);
             objDB.AddInParameter(sprocCmd, COLUMN_NAME_STATUS, DbType.Int16, objEntity.Status);
             objDB.AddOutParameter(sprocCmd, COLUMN_NAME_RESULT, DbType.Int32, result);
             objDB.ExecuteNonQuery(sprocCmd);
             result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_RESULT));
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
     }
     return result;
 }
        public ActionResult Report(string strFromDate, string strToDate, int filterId = 0)
        {
            Student2ViewModel objEntity = new Student2ViewModel();
            var objStudent2Repository = new Student2Repository();
            objEntity.Student2ReportList = new List<Student2ViewModel>();

            if (string.IsNullOrEmpty(strFromDate))
            {
                objEntity.FromDate = null;

            }
            else
            {
                objEntity.strFromDate = strFromDate;
                objEntity.FromDate = Convert.ToDateTime(strFromDate);
            }
            if (string.IsNullOrEmpty(strToDate))
            {
                objEntity.ToDate = null;

            }
            else
            {
                objEntity.strToDate = strToDate;
                objEntity.ToDate = Convert.ToDateTime(strToDate);
            }

            objEntity.CourseId = filterId;
            objEntity.filterId = filterId;

            #region DatabaseDropdown

            var objCourseRepository = new CourseRepository();
            var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel());
            objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle");

            #endregion

            if (objEntity.FromDate.HasValue && objEntity.ToDate.HasValue && objEntity.FromDate > objEntity.ToDate)
            {
                this.Flash("Warning", "From Date is smaller than To Date.");
                return View(objEntity);

            }

            objEntity.Student2ReportList = objStudent2Repository.Report(StudentFlags.SelectAllByReport.GetHashCode(), objEntity);

            if (objEntity.Student2ReportList.Count == 0 && (!string.IsNullOrEmpty(strFromDate) || !string.IsNullOrEmpty(strToDate) || filterId > 0))
            {
                this.Flash("Warning", "No matching records found.");
            }

            return View(objEntity);
        }
        public ActionResult Details(int id)
        {
            Student2Repository objStudent2Repository = new Student2Repository();
            Student2ViewModel objEntity = new Student2ViewModel();

            objEntity = objStudent2Repository.Select(StudentFlags.SelectByID.GetHashCode(), new Student2ViewModel()
            {
                StudentId = id
            }).FirstOrDefault();
            if (objEntity == null)
            {

                return RedirectToAction("Index");
            }

            return View(objEntity);
        }
        public Student2ViewModel Insert(Student2ViewModel objEntity)
        {
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_STUDENT2_VIEWMODEL_INSERT))
                {

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_NAME, DbType.String, objEntity.Name);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_GENDER, DbType.Int16, objEntity.Gender);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CURRENTDATE, DbType.DateTime, objEntity.CurrentDate);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CURRENTTIME, DbType.DateTime, objEntity.CurrentTime);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CURRENTDATETIME, DbType.DateTime, objEntity.CurrentDateTime);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CHECKBOX, DbType.Boolean, objEntity.Checkbox);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_RADIOBUTTON, DbType.Int16, objEntity.RadioButton);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_FILENAME, DbType.String, objEntity.FileName);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_STATEID, DbType.Int32, objEntity.StateId);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_COURSEID, DbType.Int32, objEntity.CourseId);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_STATUS, DbType.Int32, objEntity.Status);

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CREATEDBY, DbType.Int32, objEntity.CreatedBy);

                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_STUDENTID, DbType.Int32, objEntity.StudentId);
                    objDB.AddOutParameter(sprocCmd, COLUMN_NAME_RESULT, DbType.Int32, objEntity.Result);
                    objDB.ExecuteNonQuery(sprocCmd);
                    objEntity.StudentId = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_STUDENTID));
                    objEntity.Result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, COLUMN_NAME_RESULT));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return objEntity;
        }
        // GET: Student2
        public ActionResult Create()
        {
            Student2ViewModel objEntity = new Student2ViewModel();

            #region DatabaseDropdown
            var objCourseRepository = new CourseRepository();
            var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel());
            objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle");
            #endregion

            #region DatabaseOptionGroup

            CountryStateRepository objCountryStateRepository = new CountryStateRepository();
            var objCountryStateEntityList = objCountryStateRepository.Select(CountryStateFlags.SelectAllForOptionGroup.GetHashCode(), new CountryStateViewModel());
            objEntity.SelectCountryList = new SelectList(objCountryStateEntityList, "StateId", "StateName", "CountryName", 1);
            #endregion

            objEntity.CurrentDate = DateTime.Now;

            objEntity.CurrentDateTime = DateTime.Now;

            return View(objEntity);
        }
        // GET: Student3
        public ActionResult Search(string Keyword)
        {
            if (!string.IsNullOrWhiteSpace(Keyword) || !string.IsNullOrEmpty(Keyword))
            {
                Keyword = Keyword.Trim();
            }
            var objEntity = new Student2ViewModel()
            {
                Keyword = Keyword
            };

            var objStudent2Repository = new Student2Repository();
            // objEntity.Student2SearchList = new List<Student2ViewModel>();

            objEntity.Student2SearchList = objStudent2Repository.Search(StudentFlags.SelectAllByKeyword.GetHashCode(), objEntity);

            if (objEntity.Student2SearchList.Count >= 0 && !string.IsNullOrWhiteSpace(Keyword))
            {

                this.Flash("Success", string.Format("Your search for '{0}' returns {1} result(s).", Keyword, objEntity.Student2SearchList.Count().ToString()));
            }
            else if (objEntity.Student2SearchList.Count == 0)
            {
                this.Flash("Warning", string.Format(@"Your search returns {0} result(s)", 0));
                //flash message
            }

            return View(objEntity);
        }
        public ActionResult Create(Student2ViewModel objEntity)
        {
            Student2Repository objStudent2Repository = new Student2Repository();
            CountryStateRepository objCountryStateRepository = new CountryStateRepository();
            string fileName = string.Empty;

            if (ModelState.IsValid)
            {
                objEntity.Status = StatusEnum.Active;

                objEntity.CreatedBy = 1;//admin userid

                #region FileUpload

                if (objEntity.UploadFile != null)
                {
                    fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UploadFile.FileName);
                    objEntity.FileName = fileName;

                }
                else
                {
                    objEntity.FileName = string.Empty;
                }

                #endregion
                objEntity = objStudent2Repository.Insert(objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {

                    #region FileUpload

                    //file name
                    if (objEntity.UploadFile != null)
                    {
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), fileName);
                        // WebImage.Save()
                        objEntity.UploadFile.SaveAs(path);
                    }

                    #endregion
                    //   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");
                }

            }
            #region DatabaseDropdown
            var objCourseRepository = new CourseRepository();
            var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel());
            objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle");
            #endregion

            #region DatabaseOptionGroup

            var objCountryStateEntityList = objCountryStateRepository.Select(CountryStateFlags.SelectAllForOptionGroup.GetHashCode(), new CountryStateViewModel());
            objEntity.SelectCountryList = new SelectList(objCountryStateEntityList, "StateId", "StateName", "CountryName", 1);
            #endregion
            return View(objEntity);
        }
        public ActionResult Edit(int id, Student2ViewModel objEntity)
        {
            Student2Repository objStudent2Repository = new Student2Repository();
            CountryStateRepository objCountryStateRepository = new CountryStateRepository();
            string fileName = string.Empty;
            string oldFileName = string.Empty;

            if (ModelState.IsValid)
            {
                objEntity.Name = objEntity.Name.Trim();
                objEntity.StudentId = id;
                oldFileName = objEntity.FileName;

                #region FileUpload

                if (objEntity.UploadFile != null)
                {
                    fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UploadFile.FileName);
                    objEntity.FileName = fileName;
                }

                #endregion

                objEntity = objStudent2Repository.Update(StudentFlags.UpdateByID.GetHashCode(), objEntity);
                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    #region FileUpload
                    //delete old file

                    //file name
                    if (objEntity.UploadFile != null)
                    {
                        if (!string.IsNullOrEmpty(objEntity.UploadFile.FileName))
                        {
                            ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), oldFileName));
                        }
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), fileName);
                        // WebImage.Save()
                        objEntity.UploadFile.SaveAs(path);
                    }

                    #endregion
                    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");
                }
            }
            #region DatabaseDropdown
            var objCourseRepository = new CourseRepository();
            var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel());
            objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle");
            #endregion

            #region DatabaseOptionGroup

            var objCountryStateEntityList = objCountryStateRepository.Select(CountryStateFlags.SelectAllForOptionGroup.GetHashCode(), new CountryStateViewModel());
            objEntity.SelectCountryList = new SelectList(objCountryStateEntityList, "StateId", "StateName", "CountryName", 1);
            #endregion

            return View(objEntity);
        }
        public ActionResult Edit(int id)
        {
            Student2Repository objStudent2Repository = new Student2Repository();
            Student2ViewModel objEntity = new Student2ViewModel();
            CountryStateRepository objCountryStateRepository = new CountryStateRepository();

            objEntity = objStudent2Repository.Select(StudentFlags.SelectByID.GetHashCode(), new Student2ViewModel()
            {
                StudentId = id

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

                return RedirectToAction("Index");
            }
            objEntity.CurrentTimeValue = objEntity.CurrentTime.HasValue ? objEntity.CurrentTime.Value.ToString("hh:mm tt") : string.Empty;

            #region DatabaseDropdown
            var objCourseRepository = new CourseRepository();
            var objCourseViewModelEntity = objCourseRepository.Select(CourseFlags.SelectAll.GetHashCode(), new CourseViewModel());
            objEntity.CourseList = new SelectList(objCourseViewModelEntity.Select(model => new { model.CourseId, model.CourseTitle }), "CourseId", "CourseTitle");
            #endregion

            #region DatabaseOptionGroup

            var objCountryStateEntityList = objCountryStateRepository.Select(CountryStateFlags.SelectAllForOptionGroup.GetHashCode(), new CountryStateViewModel());
            objEntity.SelectCountryList = new SelectList(objCountryStateEntityList, "StateId", "StateName", "CountryName", 1);
            #endregion
            return View(objEntity);
        }
Пример #10
0
        public ActionResult Delete(int id)
        {
            int result = 0;
            Student2Repository objStudent2Repository = new Student2Repository();

            Student2ViewModel objEntity = new Student2ViewModel();
            CountryStateRepository objCountryStateRepository = new CountryStateRepository();

            objEntity = objStudent2Repository.Select(StudentFlags.SelectByID.GetHashCode(), new Student2ViewModel()
            {
                StudentId = id

            }).FirstOrDefault();
            if (objEntity == null)
            {
                //delete old file

                ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_STUDENT_IMAGE_PATH), objEntity.FileName));
            }

            result = objStudent2Repository.Delete(StudentFlags.DeleteByID.GetHashCode(), new Student2ViewModel()
            {
                StudentId = id,

            });
            if (result == ResultFlags.Success.GetHashCode())
            {
                this.Flash("success", "Student Delete successfully");
                return RedirectToAction("Index");
            }
            else if (result == ResultFlags.Failure.GetHashCode())
            {
                this.Flash("error", "Faild to Delete Student");
                return RedirectToAction("Index");
            }
            return RedirectToAction("Index");
        }
Пример #11
0
        public List<Student2ViewModel> Select(int Flag, Student2ViewModel objEntity)
        {
            var objEntityList = new List<Student2ViewModel>();
            try
            {
                Database objDB = base.GetDatabase();
                // Create a suitable command type and add the required parameter.
                using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SPS_STUDENT2_VIEWMODEL_SELECT))
                {
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_FLAG, DbType.Int32, Flag);

                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_STUDENTID, DbType.Int32, objEntity.StudentId);
                    objDB.AddInParameter(sprocCmd, COLUMN_NAME_CREATEDBY, DbType.Int32, objEntity.CreatedBy);

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

                            objEntityViewModel.StudentId = reader.GetColumnValue<int>(COLUMN_NAME_STUDENTID);
                            objEntityViewModel.Name = reader.GetColumnValue<string>(COLUMN_NAME_NAME);

                            objEntityViewModel.Gender = (GenderEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_GENDER);
                            objEntityViewModel.CurrentDate = reader.GetColumnValue<DateTime>(COLUMN_NAME_CURRENTDATE);
                            objEntityViewModel.CurrentTime = reader.GetColumnValue<DateTime>(COLUMN_NAME_CURRENTTIME);
                            objEntityViewModel.CurrentDateTime = reader.GetColumnValue<DateTime>(COLUMN_NAME_CURRENTDATETIME);
                            objEntityViewModel.Checkbox = reader.GetColumnValue<bool>(COLUMN_NAME_CHECKBOX);
                            objEntityViewModel.RadioButton = reader.GetColumnValue<Int16>(COLUMN_NAME_RADIOBUTTON);
                            objEntityViewModel.FileName = reader.GetColumnValue<String>(COLUMN_NAME_FILENAME);

                            objEntityViewModel.StateId = reader.GetColumnValue<Int32>(COLUMN_NAME_STATEID);
                            objEntityViewModel.CountryId = reader.GetColumnValue<Int32>(COLUMN_NAME_COUNTRYID);
                            objEntityViewModel.StateName = reader.GetColumnValue<String>(COLUMN_NAME_STATENAME);
                            objEntityViewModel.CountryName = reader.GetColumnValue<String>(COLUMN_NAME_COUNTRYNAME);

                            objEntityViewModel.CourseId = reader.GetColumnValue<int>(COLUMN_NAME_COURSEID);
                            objEntityViewModel.CourseTitle = reader.GetColumnValue<string>(COLUMN_NAME_COURSETITLE);
                            objEntityViewModel.Status = (StatusEnum)reader.GetColumnValue<Int16>(COLUMN_NAME_STATUS);

                            objEntityViewModel.CreatedBy = reader.GetColumnValue<Int32>(COLUMN_NAME_CREATEDBY);
                            objEntityViewModel.CreatedDate = reader.GetColumnValue<DateTime>(COLUMN_NAME_CREATEDDATE);

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