Ejemplo n.º 1
0
        public async Task <object> AddStudent([FromBody] StudentClassViewModel model)
        {
            StudentClass item = new SimpleAutoMapper <StudentClass>().Map(model);

            try
            {
                if (await this.CheckPermissionToAddStudent(item))
                {
                    Response response = await _classService.AddStudent(new Class()
                    {
                        ID = item.ClassID
                    }, new Student()
                    {
                        ID = item.StudentID
                    });

                    return(new
                    {
                        success = response.Success
                    });
                }

                return(Forbid());
            }
            catch (Exception e)
            {
                Response.StatusCode = StatusCode(500).StatusCode;
                return(null);
            }
        }
        public ActionResult Edit([Bind(Include = "StudentClassID,ClassName")] StudentClassViewModel studentClassViewModel)
        {
            if (!ModelState.IsValid)
            {
                // не е наред, връщаме за да се попълни/коригира
                return(View(studentClassViewModel));
            }

            // намираме модела в базата за да го редактираме
            StudentClass studentClassToUpdate = this.data.StudentClasses.Find(studentClassViewModel.StudentClassID);

            if (studentClassToUpdate == null)
            {
                return(HttpNotFound());
            }
            //сменя името
            studentClassToUpdate.ClassName = studentClassViewModel.ClassName;
            if (this.data.StudentClasses.All().Any(c => c.ClassName == studentClassToUpdate.ClassName))
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                this.data.StudentClasses.Update(studentClassToUpdate);
                this.data.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Create([Bind(Include = "StudentClassID,ClassName")] StudentClassViewModel studentClassViewModel)
        {
            if (!ModelState.IsValid)
            {
                // ако нещо не е наред, връщаме за да се попълни/коригира
                return(View(studentClassViewModel));
            }
            StudentClass newClass = new StudentClass()
            {
                ClassName = studentClassViewModel.ClassName
            };

            ViewBag.Message = "";
            if (this.data.StudentClasses.All().Any(c => c.ClassName == newClass.ClassName))
            {
                ViewBag.Message = "Класът, който се опитахте да въведете вече съществува!";
                return(RedirectToAction("Index"));
            }
            else
            {
                this.data.StudentClasses.Add(newClass);
                this.data.SaveChanges();
                ViewBag.Message = "Класът е създаден успешно!";
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> EditStudentClass(StudentClassViewModel studentClassModel)
        {
            if (ModelState.IsValid)
            {
                //get class section id
                var ClassSection = await _StudentClassRepository.GetClassSectionById(studentClassModel.Class_Id, studentClassModel.Section_Id);

                //assign new values to class subject
                StudentClass objStudentClass = new StudentClass();

                objStudentClass.StudentClass_Id = studentClassModel.StudentClass_Id;
                objStudentClass.ClassSection_id = ClassSection.ClassSection_id;
                objStudentClass.Student_Id      = studentClassModel.Student_Id;


                int result = await _StudentClassRepository.UpdateStudentClass(objStudentClass);

                if (result == 1)
                {
                    TempData["Success"] = "Student Class Updated Successfully";
                    return(RedirectToAction("studentClassDetail", "Student", new { area = "admin" }));
                }
                else
                {
                    TempData["Error"] = "Failed To Update Student Class";
                    return(RedirectToAction("studentClassDetail", "Student", new { area = "admin" }));
                }
            }

            return(View());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddStudentClass(StudentClassViewModel studentClassModel)
        {
            if (ModelState.IsValid)
            {
                var objClassSection = await _StudentClassRepository.GetClassSectionById(studentClassModel.Class_Id, studentClassModel.Section_Id);

                StudentClass studentClass = new StudentClass();
                studentClass.Student_Id      = studentClassModel.Student_Id;
                studentClass.ClassSection_id = objClassSection.ClassSection_id;



                int result = await _StudentClassRepository.AddStudentClass(studentClass);

                if (result == 1)
                {
                    TempData["Success"] = "Class Successfully Assigned To Student";
                    return(RedirectToAction("studentClassDetail", "Student", new { area = "admin" }));
                }
                else
                {
                    TempData["Error"] = "Class Assigned To Student Failed";
                    return(RedirectToAction("studentClassDetail", "Student", new { area = "admin" }));
                }
            }

            return(View());
        }
Ejemplo n.º 6
0
        public ActionResult AddClass(int id)
        {
            var viewData = new StudentClassViewModel
            {
                Student = _context.Students.Single(c => c.Id == id),
                Class   = _context.Classes.Include(c => c.ClassInfo).Include(c => c.Department).Include(c => c.Section).ToList(),
            };

            return(View("StudentClass", viewData));
        }
Ejemplo n.º 7
0
        // GET: StudentClass
        public ActionResult Index(int id)
        {
            var viewData = new StudentClassViewModel
            {
                Student      = _context.Students.Single(c => c.Id == id),
                StudentClass = _context.StudentClasses.Include(c => c.Class.ClassInfo).Include(c => c.Class.Department).Include(c => c.Class.Section).Where(c => c.StudentId == id)
            };

            return(View(viewData));
        }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            var studentClassVM = new StudentClassViewModel();

            studentClassVM.Students = _StudentRepository.GetAllStudent().ToList();

            studentClassVM.Classes = new List <SelectListItem>();
            var objClass = _StudentClassRepository.GetAllClasses().ToList();

            foreach (var lstclass in objClass)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstclass.Class_Name,
                    Value = lstclass.Class_Id.ToString(),
                };

                studentClassVM.Classes.Add(selectListItem);
            }

            studentClassVM.Sections = new List <SelectListItem>();
            var objSection = _StudentClassRepository.GetAllSections().ToList();

            foreach (var lstSection in objSection)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstSection.Section_Name,
                    Value = lstSection.Section_Id.ToString(),
                };

                studentClassVM.Sections.Add(selectListItem);
            }


            if (TempData["Error"] != null)
            {
                ViewBag.Error = TempData["Error"].ToString();
            }

            if (TempData["Success"] != null)
            {
                ViewBag.Success = TempData["Success"].ToString();
            }

            return(View(studentClassVM));
        }
Ejemplo n.º 9
0
        public ActionResult CreateCourse()
        {
            var listClass = _context.Classes.Include(c => c.Coordinator).ToList();

            var role = (from r in _context.Roles where r.Name.Contains("Student") select r)
                       .FirstOrDefault();
            var listStudent = _context.Users.Where(x => x.Roles.Select(y => y.RoleId)
                                                   .Contains(role.Id))
                              .ToList();

            var dropDownListStudentClass = new StudentClassViewModel
            {
                Classes  = listClass,
                Students = listStudent
            };

            return(View(dropDownListStudentClass));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            StudentClass foundClassDM = this.data.StudentClasses.Find(id);

            if (foundClassDM == null)
            {
                return(HttpNotFound());
            }
            StudentClassViewModel foundClassVM = new StudentClassViewModel()
            {
                StudentClassID = foundClassDM.StudentClassID,
                ClassName      = foundClassDM.ClassName
            };

            return(View(foundClassVM));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> AddStudentClass(int id)
        {
            var objStudent = await _StudentRepository.GetStudentById(id);


            var studentClassVM = new StudentClassViewModel();

            studentClassVM.Students = _StudentRepository.GetAllStudent().ToList();


            studentClassVM.Classes = new List <SelectListItem>();
            var objClass = _StudentClassRepository.GetAllClasses().ToList();

            foreach (var lstclass in objClass)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstclass.Class_Name,
                    Value = lstclass.Class_Id.ToString(),
                };

                studentClassVM.Classes.Add(selectListItem);
            }

            studentClassVM.Sections = new List <SelectListItem>();
            var objSection = _StudentClassRepository.GetAllSections().ToList();

            foreach (var lstSection in objSection)
            {
                var selectListItem = new SelectListItem
                {
                    Text  = lstSection.Section_Name,
                    Value = lstSection.Section_Id.ToString(),
                };

                studentClassVM.Sections.Add(selectListItem);
            }

            return(new JsonResult(objStudent));
        }
        // взима ViewModel на класа за триене и го връща на юзъра за потвърждение
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            StudentClass classToDelete = this.data.StudentClasses.Find(id);

            if (classToDelete == null)
            {
                return(HttpNotFound());
            }

            StudentClassViewModel classToDeleteVM = new StudentClassViewModel()
            {
                StudentClassID = classToDelete.StudentClassID,
                ClassName      = classToDelete.ClassName
            };

            return(View(classToDeleteVM));
        }
Ejemplo n.º 13
0
        public ActionResult Subject(int id, int classId)
        {
            var data = new StudentClassViewModel
            {
                Student = _context.Students.Single(c => c.Id == id),
                ClassS  = _context.Classes.Include(c => c.ClassInfo).Include(c => c.Department).Include(c => c.Section).SingleOrDefault(c => c.Id == classId),
                Results = _context.Results.Include(c => c.Subject).Where(c => c.ClassId == classId).Where(c => c.StudentId == id).ToList()
            };

            if (data.Student == null)
            {
                return(HttpNotFound());
            }
            if (data.ClassS == null)
            {
                return(HttpNotFound());
            }
            if (data.Results == null)
            {
                return(HttpNotFound());
            }

            return(View(data));
        }