public ActionResult Show1(StudentVm oSVm)
    {
        var students = _data.GetStudents(oSVm.page, oSVm.pageSize, oSVm.sort, oSVm.sortDir);

        oSVm.Students = students.ToList();
        return(View(oSVm));
    }
Пример #2
0
        public async Task <IActionResult> StudentList(int Page = 1)
        {
            Int64          Count = 1;
            List <Student> st    = _context.Student.ToList();
            List <Class>   cs    = _context.Class.ToList();

            var query = from s in st
                        join c in cs on s.ClassId equals c.ClassId
                        select new
            {
                stdntidVM      = s.StudentId,
                stdntnameVM    = s.StudentName,
                stdntclsVM     = c.ClassName,
                stdntgenderVM  = s.StudentGender,
                stdntphotoVM   = s.StudentPhoto,
                stdntcaddrssVM = s.StudentCAddress,
                stdntpaddrssVM = s.StudentPAddress,
                stdntdoaVM     = s.DateOfAdmission,
                stdntnationVM  = s.StudentNationality,
                stdntyearVM    = s.Year,
                dobVM          = s.StudentDOB,
            };

            if (query == null)
            {
                return(RedirectToAction("Error"));
            }

            List <StudentVm> sv = new List <StudentVm>();

            foreach (var item in query)
            {
                StudentVm s = new StudentVm()
                {
                    stdntidVM      = item.stdntidVM,
                    stdntnameVM    = item.stdntnameVM,
                    stdntclsNameVM = item.stdntclsVM,
                    stdntgenderVM  = item.stdntgenderVM,
                    stdntphotoVM   = item.stdntphotoVM,
                    stdntcaddrssVM = item.stdntcaddrssVM,
                    stdntpaddrssVM = item.stdntpaddrssVM,
                    stdntdoaVM     = item.stdntdoaVM,
                    stdntnationVM  = item.stdntnationVM,
                    stdntyearVM    = item.stdntyearVM,
                    dobVM          = item.dobVM,
                };
                //Assinging the counter value  of a element
                s.Serial = Count;
                Count++;
                //Add the Student to  the list
                sv.Add(s);
            }
            //Pass the List to the View


            var List = await sv.ToPagedListAsync(Page, 5);

            return(View(List));
        }
Пример #3
0
        public ActionResult DeleteConfirmed(string id)
        {
            StudentVm studentVm = db.StudentVms.Find(id);

            db.StudentVms.Remove(studentVm);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
 public bool DeleteOne(StudentVm viewModel, ref string msg)
 {
     if (!EntryChecker.IsNotZeroOrNull(viewModel.Id.GetInt(), ref msg))
     {
         return(false);
     }
     return(db.DeleteOne(MapProperties(viewModel), ref msg));
 }
Пример #5
0
        public async Task <IActionResult> Edit(int id)
        {
            StudentVm studentVm = await _studentRepo.GetSudentById(id);

            studentVm.GenderOptions = GetGenderOptions();

            return(View(studentVm));
        }
Пример #6
0
        public IActionResult Create()
        {
            var vm = new StudentVm();

            vm.GenderOptions = GetGenderOptions();

            return(View(vm));
        }
Пример #7
0
 public ActionResult PrintIndex(StudentVm aStudentVm)
 {
     // StudentVm aStudentVm = (StudentVm)TempData["student"];
     return(new Rotativa.ViewAsPdf("Save", aStudentVm)
     {
         FileName = Server.MapPath("~/Content/Student.pdf")
     });
 }
Пример #8
0
        public async Task <IList <StudentVm> > GetStudentList()
        {
            IList <Student> studentEntities = await _dbContext.Students.ToListAsync();

            IList <StudentVm> studentVms = studentEntities.Select(x => StudentVm.FromEntity(x)).ToList();

            return(studentVms);
        }
Пример #9
0
        public async Task <StudentVm> GetSudentById(int id)
        {
            Student studentEntity = await _dbContext.Students.SingleAsync(x => x.Id == id);

            StudentVm studentVm = StudentVm.FromEntity(studentEntity);

            return(studentVm);
        }
Пример #10
0
 public bool EditOne(StudentVm viewModel, ref string msg)
 {
     if (!EntryChecker.IsNotNullOrNotWhiteSpace(viewModel.Title, ref msg))
     {
         return(false);
     }
     return(db.EditOne(MapProperties(viewModel), ref msg));
 }
Пример #11
0
        public ActionResult Create()
        {
            var model = new StudentVm();

            model.GenderListItem     = GetGenderList();
            model.DepartmentListItem = GetDepartmentlist();
            return(View(model));
        }
Пример #12
0
        public async Task <List <StudentVm> > GetStudentListDapperAsync()
        {
            string strSQL = @"SELECT S.Id,S.FirstName,S.LastName,S.Email,
                                       C.Id,C.Name,
                                       SC.Id,SC.StudentId,SC.CourseId,
                                       CO.Id,CO.Name 
                                       FROM Student S
                                     LEFT JOIN Class C ON S.ClassId=C.Id
                                     LEFT JOIN StudentCourse SC ON S.Id=SC.StudentId
                                     LEFT JOIN Course CO ON SC.CourseId=CO.Id";


            List <StudentVm> students = null;

            using (IDbConnection db = new SqlConnection(_config.GetConnectionString("DatabaseConnection")))
            {
                if (db.State == ConnectionState.Closed)
                {
                    db.Open();
                }

                try
                {
                    IEnumerable <StudentVm> returnlist = await db.QueryAsync <StudentVm, ClassVm, StudentCourserVm, CourserVm, StudentVm>(strSQL, (students, classs, studentCourse, course) => {
                        if (classs != null)
                        {
                            students.Classs = classs;
                        }
                        if (studentCourse != null)
                        {
                            studentCourse.Course = course;
                            students.StudentCourse.Add(studentCourse);
                        }
                        return(students);
                    }, splitOn : "Id,Id,Id,Id");

                    students = returnlist.GroupBy(e => e.Id).Select(e =>
                    {
                        StudentVm student     = e.First();
                        student.StudentCourse = e.SelectMany(f => f.StudentCourse).ToList();
                        return(student);
                    }).ToList();

                    return(students);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (db.State == ConnectionState.Open)
                    {
                        db.Close();
                    }
                }
            }
        }
Пример #13
0
        public void Put(int id, StudentVm student)
        {
            var st = _dbContext.Students.SingleOrDefault(_st => _st.Id == id);

            _dbContext.Students.Attach(st);
            _dbContext.Entry(st).State = EntityState.Modified;
            _dbContext.Entry(st).CurrentValues.SetValues(student);
            _dbContext.SaveChanges();
        }
Пример #14
0
        private static IList <SelectListItem> GetGenderOptions()
        {
            IList <SelectListItem> options = StudentVm.GetGenderOptions().
                                             Select(x => new SelectListItem {
                Text = x.Value, Value = x.Key
            }).
                                             ToList();

            return(options);
        }
Пример #15
0
        public ActionResult AddStudent()
        {
            var data  = db.Genders.ToList();
            var StdVm = new StudentVm()
            {
                Genders = data,
            };

            return(View(StdVm));
        }
Пример #16
0
 public ActionResult Edit([Bind(Include = "Id,Crebo,Slb,Group,Username")] StudentVm studentVm)
 {
     if (ModelState.IsValid)
     {
         db.Entry(studentVm).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(studentVm));
 }
Пример #17
0
        public ActionResult Edit(StudentVm model)
        {
            if (ModelState.IsValid)
            {
                _studentVmMapper.SaveViewModel(model);
                _unitOfWork.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public HttpResponseMessage Post(HttpRequestMessage request, StudentVm student)
        {
            //_studentregistrationService.Register(student);
            //return new HttpResponseMessage(HttpStatusCode.InternalServerError);

            if (ModelState.IsValid)
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            return(request.CreateResponse(HttpStatusCode.BadRequest, GetErrorMessage()));
        }
Пример #19
0
 public StudentVm GetOne(StudentVm p, ref string msg)
 {
     try
     {
         var x = GetList(p, ref msg).Single();
         return(x);
     }
     catch (Exception)
     {
         return(new StudentVm());
     }
 }
Пример #20
0
        public List <StudentVm> GetList(StudentVm p, ref string msg)
        {
            MySqlCommand command = new MySqlCommand();

            command.CommandText = "GetStudents";
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.AddWithValue("intId", p.Id.GetInt()).Direction                        = ParameterDirection.Input;
            command.Parameters.AddWithValue("strLrn", p.LRN).Direction                               = ParameterDirection.Input;
            command.Parameters.AddWithValue("strLastName", p.LastName).Direction                     = ParameterDirection.Input;
            command.Parameters.AddWithValue("strFirstName", p.FirstName).Direction                   = ParameterDirection.Input;
            command.Parameters.AddWithValue("strMiddleName", p.MiddleName).Direction                 = ParameterDirection.Input;
            command.Parameters.AddWithValue("strSectionName", p.Section).Direction                   = ParameterDirection.Input;
            command.Parameters.AddWithValue("strGradeName", p.Grade).Direction                       = ParameterDirection.Input;
            command.Parameters.AddWithValue("intSchoolYearId", p.SchoolYearId).Direction             = ParameterDirection.Input;
            command.Parameters.AddWithValue("strCurrentSectionName", p.CurrentSectionName).Direction = ParameterDirection.Input;

            List <StudentVm> items = new List <StudentVm>();
            DataTable        dt    = MyHelper.GetData(command, ref msg);

            try
            {
                if (dt.Rows.Count <= 0)
                {
                    return(items);
                }
                foreach (DataRow row in dt.Rows)
                {
                    StudentVm item = new StudentVm();
                    item.Id                       = row["StudentId"].GetString();
                    item.LRN                      = row["Lrn"].GetString(); item.LastName = row["LastName"].GetString();
                    item.FirstName                = row["FirstName"].GetString();
                    item.MiddleName               = row["MiddleName"].GetString();
                    item.GradeId                  = row["GradeId"].GetString();
                    item.Grade                    = row["GradeName"].GetString();
                    item.SectionId                = row["SectionId"].GetString();
                    item.Section                  = row["SectionName"].GetString();
                    item.SchoolYearId             = row["SchoolYearId"].GetString();
                    item.SchoolYear               = row["SchoolYearName"].GetString();
                    item.CurrentGradeAndSectionId = row["CurrentGradeAndSectionId"].GetString();
                    item.CurrentSectionName       = row["CurrentSectionName"].GetString();

                    items.Add(item);
                }

                return(items);
            }
            catch (Exception ex)
            {
                msg = ef.GetExceptionMessage(ex, msg);
                return(new List <StudentVm>());
            }
        }
Пример #21
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            var stdVm = new StudentVm();

            stdVm.Name = searchTextBox.Text;

            if (db.SearchStudents(stdVm.Name) != null)
            {
                studentVmBindingSource.DataSource = null;
                studentVmBindingSource.DataSource = db.SearchStudents(stdVm.Name);
            }
        }
Пример #22
0
 public StudentVm GetOne(StudentVm p, ref string msg)
 {
     try
     {
         return(GetList(p, ref msg).Single());
     }
     catch (Exception ex)
     {
         msg = ef.GetExceptionMessage(ex, msg);
         return(new StudentVm());
     }
 }
Пример #23
0
        public void Update(StudentVm studentVm)
        {
            if (studentVm == null)
            {
                throw new ArgumentNullException("Value is a null");
            }

            var studentEntity = Mapper.Map <Student>(studentVm);

            _dbContext.Users.Update(studentEntity);
            _dbContext.SaveChanges();
        }
Пример #24
0
        public async Task <IActionResult> Create(StudentVm vm)
        {
            if (ModelState.IsValid == false)
            {
                vm.GenderOptions = GetGenderOptions();
                return(View(vm));
            }

            var id = await _studentRepo.Create(vm);

            return(RedirectToAction(nameof(Details), new { id }));
        }
Пример #25
0
        // view invoke logic
        public IViewComponentResult Invoke()
        {
            var sCount = _StudentRepo.GetAllStudents().Count;
            var vm     = new StudentVm
            {
                TotalCount = sCount
            };

            //3: create a view component razor page
            // 4:pass data into component
            return(View(sCount));
        }
Пример #26
0
        public async Task Edit(StudentVm vm)
        {
            Student trackedEntity = await _dbContext.Students.SingleAsync(x => x.Id == vm.Id);

            trackedEntity.FirstName   = vm.FirstName;
            trackedEntity.LastName    = vm.LastName;
            trackedEntity.StudentCode = vm.StudentCode;
            trackedEntity.Gender      = vm.GenderValue;
            trackedEntity.UpdatedAt   = DateTime.UtcNow;

            await _dbContext.SaveChangesAsync();
        }
Пример #27
0
 public ActionResult Create(StudentVm model)
 {
     if (ModelState.IsValid)
     {
         var  students = Mapper.Map <Student>(model);
         bool isSave   = _studentManager.Add(students);
         if (isSave)
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View());
 }
Пример #28
0
        // GET: Students/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentVm studentVm = db.StudentVms.Find(id);

            if (studentVm == null)
            {
                return(HttpNotFound());
            }
            return(View(studentVm));
        }
        public ActionResult AddStudent()
        {
            var data        = db.Genders.ToList();
            var classdata   = db.Classes.ToList();
            var SectionList = db.ClassSections.ToList();
            var StdVm       = new StudentVm()
            {
                Genders       = data,
                Classes       = classdata,
                ClassSections = SectionList
            };

            return(View(StdVm));
        }
Пример #30
0
        private Student MapProperties(StudentVm p)
        {
            Student baseObj = new Student();

            baseObj.Id                = p.Id.GetInt();
            baseObj.Lrn               = p.LRN.GetString();
            baseObj.LastName          = p.LastName.GetString();
            baseObj.FirstName         = p.FirstName.GetString();
            baseObj.MiddleName        = p.MiddleName.GetString();
            baseObj.GradeAndSectionId = LoadGradeAndSections(p.Grade, p.Section);
            baseObj.SchoolYearId      = p.SchoolYearId.GetInt();

            return(baseObj);
        }
Пример #31
0
        public ActionResult EditStudentModal(int id = 0)
        {
            if (id == 0)
                return View("Students/_EditStudentModal", new StudentVm());
            var student = dispatcher.Query(new GetEntityByIdQuery<Student>(id));

            var studentVm = new StudentVm(student);

            return View("Students/_EditStudentModal", studentVm);
        }
 public HttpResponseMessage Post(StudentVm student)
 {
     return new HttpResponseMessage(HttpStatusCode.OK);
 }
Пример #33
0
        public string EditStudent(StudentVm data)
        {
            var currUser = dispatcher.Query(new GetEntitiesQuery<Teacher>()).First(t => RouteData != null && t.Email == RouteData.Values["user"].ToString());

            if (currUser.IsAdmin != null && (bool)!currUser.IsAdmin)
            {
                Response.SuppressFormsAuthenticationRedirect = true;
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 401;
                return "AutorizationFailed";
            }

            if (!data.Id.IsEmpty())
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "IdIsEmpty";
            }

            if (data.FullName.IsNullOrWhiteSpace())
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "NameIsEmpty";
            }

            if (data.Email.IsNullOrWhiteSpace())
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "EmailIsEmpty";
            }

            if (data.Skype.IsNullOrWhiteSpace())
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "SkypeIsEmpty";
            }

            var student = dispatcher.Query(new GetEntityByIdQuery<Student>(data.Id));
            if (student == null)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "NonExistent";
            }

            if (data.TeacherId != null)
            {
                var teacher = dispatcher.Query(new GetEntityByIdQuery<Teacher>(data.TeacherId));
                student.Teacher = teacher;
            }

            if (data.LenguageId != 0)
            {
                var lenguage = dispatcher.Query(new GetEntityByIdQuery<Language>(data.LenguageId));
                student.Language = lenguage;
            }

            student.FullName = data.FullName;
            student.Email = data.Email;
            student.Skype = data.Skype;

            dispatcher.Push(new EditStudentCommand(student));
            return "Success";
        }
Пример #34
0
        public object AddStudent(StudentVm data)
        {
            var currUser = dispatcher.Query(new GetEntitiesQuery<Teacher>()).First(t => RouteData != null && t.Email == RouteData.Values["user"].ToString());

            if (currUser.IsAdmin != null && (bool)!currUser.IsAdmin)
            {
                Response.SuppressFormsAuthenticationRedirect = true;
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 401;
                return "AutorizationFailed";
            }

            if (data.FullName.IsEmpty())
            {
                Response.SuppressFormsAuthenticationRedirect = true;
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "NameIsEmpty";
            }

            if (data.Email.IsEmpty())
            {
                Response.SuppressFormsAuthenticationRedirect = true;
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "EmailIsEmpty";
            }

            if (data.Skype.IsEmpty())
            {
                Response.SuppressFormsAuthenticationRedirect = true;
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 400;
                return "SkypeIsEmpty";
            }

            var student = new Student
            {
                FullName = data.FullName,
                Email = data.Email,
                Skype = data.Skype
            };
            dispatcher.Push(new EditStudentCommand(student));

            return "Success";
        }