public ActionResult Presence(int subjectId)
        {
            // Get the specified subject.
            var subject = _subjectRepository.GetById(subjectId);

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

            // Get the current presence.
            int studentId = Student.Id;
            var presence  = _presenceRepository.GetByStudent(studentId);

            // Map the subject to a view model.
            var subjectModel = Mapper.Map <SubjectModel>(subject);

            // Create the presence view model.
            var presenceModel = new PresenceModel
            {
                Subject = subjectModel,
                // Check if student is already present.
                AlreadyPresent = presence.Any(p => p.IsPresent(subjectId, studentId)),
                PastSubject    = subject.IsPastSubject()
            };

            return(View(presenceModel));
        }
示例#2
0
        public IHttpActionResult GetSubjectById(int id)
        {
            var subject = subjectRepo.GetById(id);

            if (subject == null)
            {
                return(Content(HttpStatusCode.NotFound, "Item does not exist"));
            }

            return(Ok(subject));
        }
示例#3
0
        public ActionResult ExportSubjectGrade(int id)
        {
            Subject           subject           = new Subject();
            SubjectRepository subjectRepository = new SubjectRepository();

            subject = subjectRepository.GetById(id);
            Export    export     = new Export();
            DataTable gradeTable = export.SubjectGrades(subject);

            GridView Grid = new GridView();

            Grid.DataSource = gradeTable;
            Grid.DataBind();

            string filename = "attachment; filename=" + subject.Name + "_" + ".xls";

            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", filename);
            Response.ContentType = "application/ms-excel";

            Response.Charset = "";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            Grid.RenderControl(htw);

            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
            return(View());
        }
示例#4
0
 public ActionResult EditSubjects(int id, AdminControllerSubjectVM subjectModel)
 {
     TryUpdateModel(subjectModel);
     if (ModelState.IsValid)
     {
         Subject           subject           = null;
         SubjectRepository subjectRepository = new SubjectRepository();
         if (id > 0)
         {
             subject      = subjectRepository.GetById(id);
             subject.Name = subjectModel.Name;
             subjectRepository.Save(subject);
             return(RedirectToAction("ManageSubjects"));
         }
         else
         {
             subject = subjectRepository.GetAll(filter: s => s.Name == subjectModel.Name).FirstOrDefault();
             if (subject == null)
             {
                 subject      = new Subject();
                 subject.Name = subjectModel.Name;
                 subjectRepository.Save(subject);
                 return(RedirectToAction("ManageSubjects"));
             }
             else
             {
                 throw new ArgumentException("Invalid subject name");
             }
         }
     }
     return(View(subjectModel));
 }
示例#5
0
        public ActionResult SubjectIndex(Guid id)
        {
            var subjectRepository = new SubjectRepository(_context);
            var subject           = subjectRepository.GetById(id);
            var viewModel         = SubjectViewModel.FromEntity(subject, 3);

            return(PartialView("_SubjectIndex", viewModel));
        }
示例#6
0
        public void testGetById()
        {
            // Arrange
            int count = repo.All().Count();

            Subject c = repo.All().FirstOrDefault();

            Assert.NotNull(c);


            // Act
            Subject actual = repo.GetById(c.Id);

            // Assert

            Assert.NotNull(actual);
        }
        public ActionResult Edit(int id)
        {
            // Get the subject by its id.
            var subjects = _subjectRepository.GetById(id);

            if (subjects == null)
            {
                return(RedirectToAction("List"));
            }

            // Map the subject to a view model.
            var model = Mapper.Map <SubjectModel>(subjects);

            // Prepare the view model.
            model.StartDateString = model.StartDate.ToString("dd-MM-yyyy HH:mm");
            model.EndDateString   = model.EndDate.ToString("dd-MM-yyyy HH:mm");
            PrepareSubjectModel(model);

            return(View(model));
        }
示例#8
0
        public IHttpActionResult Get(int tid, int sid)
        {
            List <Subject> subList = techRepo.GetSubjectByTeacher(tid);

            Subject subject = subRepo.GetById(sid);
            bool    check   = false;

            foreach (var item in subList)
            {
                if (item.SubjectId == subject.SubjectId)
                {
                    check = true;
                }
            }

            if (subject == null || check == false)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            return(Ok(subject));
        }
示例#9
0
        public ActionResult Edit(Guid id)
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);

            var knowledgeAreas = knowledgeAreaRepository.ListActiveKnowledgeAreas();

            ViewBag.KnowledgeAreas = new SelectList(knowledgeAreas, "Id", "Name");

            var subjectRepository = new SubjectRepository(_context);
            var subject           = subjectRepository.GetById(id);

            return(View(SubjectViewModel.FromEntity(subject, 0)));
        }
示例#10
0
        public void Get_subject_by_id_test()
        {
            var repo   = new SubjectRepository(context);
            var model  = new SubjectEntity("AM", "Analiza matematyczna");
            var model2 = new SubjectEntity("MD", "Matematyka dyskretna");

            repo.AddNew(model);
            repo.AddNew(model2);
            var result = repo.GetById(model2.Id);

            Assert.IsNotNull(result);
            Assert.AreEqual(model2.Id, result.Id);
        }
        public ActionResult Delete(int id)
        {
            SubjectRepository repository = new SubjectRepository();
            Subject           subject    = repository.GetById(id);

            SubjectViewModel model = new SubjectViewModel();

            model.Title       = subject.Title;
            model.Description = subject.Description;
            model.Credits     = subject.Credits;
            model.TeacherId   = subject.TeacherId;

            return(View(model));
        }
        static void Main(string[] args)
        {
            string connString = ConfigurationManager.ConnectionStrings["TrainingDB"].ToString();

            try
            {
                SQLHelper.Initialize(connString);
                SQLHelper.AssureDatabase("Subjects");
                SQLHelper.AssureDatabase("Students");
                SQLHelper.AssureDatabase("StudentsXSubjects");
                StudentRepository studentRepository = new StudentRepository();

                //StudentEntity student = new StudentEntity();
                //student.Name = "Draghici";
                //student.Surname = "Alice";
                //student.PhoneNo = "0724059799";
                //studentRepository.Add(student);

                //StudentEntity student2 = new StudentEntity();
                //student2.Name = "Pavel";
                //student2.Surname = "Marcela";
                //student2.PhoneNo = "0729874154";
                //studentRepository.Add(student2);

                SubjectRepository subjectRepository = new SubjectRepository();

                //SubjectEntity subject1 = new SubjectEntity();
                //subject1.Description = "Matematica";
                //SubjectEntity subject2 = new SubjectEntity();
                //subject2.Description = "Algebra";
                //subjectRepository.Add(subject1);
                //subjectRepository.Add(subject2);
                //subject2.Description = "Franceza";
                //subjectRepository.Update(1, subject2);
                //subjectRepository.Delete(4);
                //subjectRepository.Delete(5);
                //subjectRepository.Delete(6);

                var subjects    = subjectRepository.Get();
                var subjectById = subjectRepository.GetById(2);
                studentRepository.AssignToSubject(7, 2);
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
        public ActionResult Edit(int?id)
        {
            SubjectRepository repository = new SubjectRepository();
            SubjectViewModel  model      = new SubjectViewModel();

            if (id.HasValue)
            {
                Subject subject = repository.GetById(id.Value);
                model.Id          = subject.Id;
                model.Title       = subject.Title;
                model.Description = subject.Description;
                model.Credits     = subject.Credits;
                model.Teachers    = PopulateTeacherList();
                model.TeacherId   = subject.TeacherId;
            }

            return(View(model));
        }
示例#14
0
        public ActionResult EditSubjects(int id)
        {
            Subject                  subject           = new Subject();
            SubjectRepository        subjectRepository = new SubjectRepository();
            AdminControllerSubjectVM subjectModel      = new AdminControllerSubjectVM();

            if (id > 0)
            {
                subject                = subjectRepository.GetById(id);
                subjectModel.Name      = subject.Name;
                subjectModel.SubjectID = id;
            }
            if (id == 0)
            {
                subject.Name = subjectModel.Name;
            }
            return(View(subjectModel));
        }
示例#15
0
 public SubjectDM GetById(int id)
 {
     try
     {
         return(_SubjectRepo.GetById(id));
     }
     catch (Exception ex)
     {
         //Errors in this scope indicates system error (not validation errors)
         //If error not handled, log it and add system error
         if (!_GlobalErrors.ErrorHandled)
         {
             _Logger.Error(ex, "Database Error: Cannot Get Specific Subject!");
             _GlobalErrors.AddSystemError("Database Error: Cannot Get Specific Subject!");
             _GlobalErrors.ErrorHandled = true;
         }
         throw;
     }
 }
示例#16
0
        public JsonResult DeleteSubject(int id)
        {
            bool subjectInUse = false;
            CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
            List <Course>           courseList = new List <Course>();

            courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
            if (courseList.Count > 0)
            {
                subjectInUse = true;
            }
            else
            {
                SubjectRepository subjectRepository = new SubjectRepository();
                Subject           subject           = new Subject();
                subject = subjectRepository.GetById(id);
                subjectRepository.Delete(subject);
            }
            return(Json(subjectInUse, JsonRequestBehavior.AllowGet));
        }
示例#17
0
        public ActionResult Edit(Guid id, CourseViewModel viewModel)
        {
            var subjectRepository = new SubjectRepository(_context);
            var userRepository    = new UserRepository(_context);

            if (ModelState.IsValid)
            {
                try
                {
                    var subject          = subjectRepository.GetById(viewModel.SubjectId);
                    var teacher          = (Teacher)userRepository.GetById(viewModel.TeacherInChargeId);
                    var courseRepository = new CourseRepository(_context);

                    courseRepository.UpdateWithClasses(CourseViewModel.ToEntity(viewModel, subject, teacher));
                    _context.Save(_loggedUser);

                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = Resource.CourseUpdatedToastrMessage;
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }


            var activeSubjects = subjectRepository.ListActiveSubjects();

            ViewBag.Subjects = new SelectList(activeSubjects, "Id", "Name");

            var activeTeachers = userRepository.ListActiveTeachers();

            ViewBag.Teachers = new SelectList(activeTeachers, "Id", "Name");

            return(View(viewModel));
        }
        public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId)
        {
            Grade           grade     = new Grade();
            GradeRepository gradeRepo = new GradeRepository();
            SelectListItem  gradeItem = null;

            if (gradeId != 0)
            {
                grade            = gradeRepo.GetById(gradeId);
                gradeValue       = System.Math.Round(gradeValue, 2);
                grade.GradeValue = gradeValue;
                gradeRepo.Save(grade);
            }
            else
            {
                UnitOfWork        unitOfWork        = new UnitOfWork();
                StudentRepository studentRepository = new StudentRepository(unitOfWork);
                GradeRepository   gradeRepository   = new GradeRepository(unitOfWork);
                SubjectRepository subjectRepository = new SubjectRepository(unitOfWork);
                Student           student           = new Student();
                student = studentRepository.GetById(studentId);
                Subject subject = new Subject();
                subject          = subjectRepository.GetById(subjectId);
                grade.SubjectID  = subjectId;
                grade.Subject    = subject;
                grade.Student    = student;
                gradeValue       = System.Math.Round(gradeValue, 2);
                grade.GradeValue = gradeValue;
                gradeRepository.Save(grade);
                unitOfWork.Commit();
            }
            gradeItem = new SelectListItem()
            {
                Text = grade.GradeValue.ToString(), Value = grade.Id.ToString()
            };
            return(Json(gradeItem, JsonRequestBehavior.AllowGet));
        }
示例#19
0
        public ActionResult Index(Guid id)
        {
            var subjectRepository = new SubjectRepository(_context);


            var subject = subjectRepository.GetById(id);

            if (!subject.Active)
            {
                TempData["MessageType"]  = "warning";
                TempData["MessageTitle"] = Resource.WarningToastrTitle;
                TempData["Message"]      = Resource.SubjectNotAvailableToastrMessage;
                return(RedirectToAction("Index", "Home"));
            }

            var viewModel = SubjectViewModel.FromEntity(subject, 3);

            ViewBag.OtherSubjects =
                new SelectList(subject.KnowledgeArea.Subjects.Where(a => a.Active).Except(new List <Subject> {
                subject
            }),
                               "Id", "Name");
            return(View(viewModel));
        }
 public JsonResult DeleteSubject(int id)
 {
     bool subjectInUse = false;
     CourseSubjectRepository courseSubjectRepository = new CourseSubjectRepository();
     List<Course> courseList = new List<Course>();
     courseList = courseSubjectRepository.GetAll(filter: cs => cs.Subject.Id == id).Select(c => c.Course).ToList();
     if (courseList.Count > 0)
     {
         subjectInUse = true;
     }
     else
     {
         SubjectRepository subjectRepository = new SubjectRepository();
         Subject subject = new Subject();
         subject = subjectRepository.GetById(id);
         subjectRepository.Delete(subject);
     }
     return Json(subjectInUse, JsonRequestBehavior.AllowGet);
 }
        public ActionResult EditSubjects(int id, AdminControllerSubjectVM subjectModel)
        {
            TryUpdateModel(subjectModel);
            if (ModelState.IsValid)
            {

                Subject subject = null;
                SubjectRepository subjectRepository = new SubjectRepository();
                if (id > 0)
                {
                    subject = subjectRepository.GetById(id);
                    subject.Name = subjectModel.Name;
                    subjectRepository.Save(subject);
                    return RedirectToAction("ManageSubjects");
                }
                else
                {
                    subject = subjectRepository.GetAll(filter: s => s.Name == subjectModel.Name).FirstOrDefault();
                    if (subject == null)
                    {
                        subject = new Subject();
                        subject.Name = subjectModel.Name;
                        subjectRepository.Save(subject);
                        return RedirectToAction("ManageSubjects");
                    }
                    else
                    {
                        throw new ArgumentException("Invalid subject name");
                    }
                }
            }
            return View(subjectModel);
        }
示例#22
0
        public ActionResult EditArticle(int id)
        {
            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                ArticleControllerArticlesVM model             = new ArticleControllerArticlesVM();
                TeacherRepository           teacherRepository = new TeacherRepository();
                Article               article           = new Article();
                ArticleRepository     articleRepository = new ArticleRepository();
                List <Subject>        subjectList       = new List <Subject>();
                SubjectRepository     subjectRepository = new SubjectRepository();
                Teacher               teacher           = new Teacher();
                List <SelectListItem> listSubjects      = new List <SelectListItem>();
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List <int> subjectId = new List <int>();
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
                subjectId = subjectId.Distinct().ToList();
                foreach (var item in subjectId)
                {
                    subjectList.Add(subjectRepository.GetById(item));
                }

                if (id > 0)
                {
                    article            = articleRepository.GetById(id);
                    model.ArticleId    = article.Id;
                    model.TeacherID    = teacher.Id;
                    model.Title        = article.Title;
                    model.Content      = article.Content;
                    model.DateCreated  = article.DateCreated;
                    model.DateModified = article.DateModified;
                    model.Subject      = article.Subject;
                    model.Teacher      = teacher;
                    listSubjects.Add(new SelectListItem()
                    {
                        Text = article.Subject.Name, Value = article.Subject.Id.ToString(), Selected = true
                    });
                }
                if (id == 0)
                {
                    model.ArticleId = 0;
                    listSubjects.Add(new SelectListItem()
                    {
                        Text = "Select subject", Value = ""
                    });
                }
                foreach (var item in subjectList)
                {
                    if (item.Id != model.ArticleId)
                    {
                        listSubjects.Add(new SelectListItem()
                        {
                            Text = item.Name, Value = item.Id.ToString()
                        });
                    }
                }
                model.SubjectsListItems = listSubjects;
                return(View(model));
            }
            return(RedirectToAction("Articles"));
        }
 public ActionResult EditJazz(int id)
 {
     return(View(subjectRepo.GetById(id)));
 }
        public ActionResult ExportSubjectGrade(int id)
        {
            Subject subject = new Subject();
            SubjectRepository subjectRepository = new SubjectRepository();
            subject = subjectRepository.GetById(id);
            Export export = new Export();
            DataTable gradeTable = export.SubjectGrades(subject);

            GridView Grid = new GridView();
            Grid.DataSource = gradeTable;
            Grid.DataBind();

            string filename = "attachment; filename=" + subject.Name + "_" + ".xls";
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", filename);
            Response.ContentType = "application/ms-excel";

            Response.Charset = "";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            Grid.RenderControl(htw);

            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
            return View();
        }
 public JsonResult EditGrade(int gradeId, double gradeValue, int subjectId, int studentId)
 {
     Grade grade = new Grade();
     GradeRepository gradeRepo = new GradeRepository();
     SelectListItem gradeItem = null;
     if (gradeId != 0)
     {
         grade = gradeRepo.GetById(gradeId);
         gradeValue = System.Math.Round(gradeValue, 2);
         grade.GradeValue = gradeValue;
         gradeRepo.Save(grade);
     }
     else
     {
         UnitOfWork unitOfWork = new UnitOfWork();
         StudentRepository studentRepository = new StudentRepository(unitOfWork);
         GradeRepository gradeRepository = new GradeRepository(unitOfWork);
         SubjectRepository subjectRepository = new SubjectRepository(unitOfWork);
         Student student = new Student();
         student = studentRepository.GetById(studentId);
         Subject subject = new Subject();
         subject = subjectRepository.GetById(subjectId);
         grade.SubjectID = subjectId;
         grade.Subject = subject;
         grade.Student = student;
         gradeValue = System.Math.Round(gradeValue, 2);
         grade.GradeValue = gradeValue;
         gradeRepository.Save(grade);
         unitOfWork.Commit();
     }
     gradeItem = new SelectListItem() { Text = grade.GradeValue.ToString(), Value = grade.Id.ToString() };
     return Json(gradeItem, JsonRequestBehavior.AllowGet);
 }
 public Subject Get(int id)
 {
     return(subjectRepository.GetById(id));
 }
        public ActionResult EditArticle(int id)
        {
            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                ArticleControllerArticlesVM model = new ArticleControllerArticlesVM();
                TeacherRepository teacherRepository = new TeacherRepository();
                Article article = new Article();
                ArticleRepository articleRepository = new ArticleRepository();
                List<Subject> subjectList = new List<Subject>();
                SubjectRepository subjectRepository = new SubjectRepository();
                Teacher teacher = new Teacher();
                List<SelectListItem> listSubjects = new List<SelectListItem>();
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List<int> subjectId = new List<int>();
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
                subjectId = subjectId.Distinct().ToList();
                foreach (var item in subjectId)
                {
                    subjectList.Add(subjectRepository.GetById(item));
                }

                if (id > 0)
                {
                    article = articleRepository.GetById(id);
                    model.ArticleId = article.Id;
                    model.TeacherID = teacher.Id;
                    model.Title = article.Title;
                    model.Content = article.Content;
                    model.DateCreated = article.DateCreated;
                    model.DateModified = article.DateModified;
                    model.Subject = article.Subject;
                    model.Teacher = teacher;
                    listSubjects.Add(new SelectListItem() { Text = article.Subject.Name, Value = article.Subject.Id.ToString(), Selected = true });
                }
                if (id == 0)
                {
                    model.ArticleId = 0;
                    listSubjects.Add(new SelectListItem() { Text = "Select subject", Value = "" });
                }
                foreach (var item in subjectList)
                {
                    if (item.Id != model.ArticleId)
                    {
                        listSubjects.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
                    }
                }
                model.SubjectsListItems = listSubjects;
                return View(model);
            }
            return RedirectToAction("Articles");
        }
        public ActionResult EditSubjects(int id)
        {
            Subject subject = new Subject();
            SubjectRepository subjectRepository = new SubjectRepository();
            AdminControllerSubjectVM subjectModel = new AdminControllerSubjectVM();

            if (id > 0)
            {
                subject = subjectRepository.GetById(id);
                subjectModel.Name = subject.Name;
                subjectModel.SubjectID = id;
            }
            if (id == 0)
            {
                subject.Name = subjectModel.Name;
            }
            return View(subjectModel);
        }