Пример #1
0
        public ActionResult AddSubject(AddSubjectViewModel model)
        {
            Subject subject = new Subject();

            subject.Name = model.SubjectName;

            if (subject.Name.IsNullOrWhiteSpace())
            {
                TempData["msg"] = "<script>alert('לא הוכנס נושא');</script>";
                return(View());
            }

            if (_subjectService.GetByName(model.SubjectName) == null)
            {
                try
                {
                    _subjectService.Add(subject);
                    foreach (var cls in _classService.All().Include(x => x.Subjects).ToList())
                    {
                        var className = cls.ClassLetter + " " + cls.ClassNumber;
                        if (className.Equals(Session["CurrentClass"].ToString()))
                        {
                            cls.Subjects.Add(subject);
                            _classService.Update(cls);
                        }
                    }
                }
                catch (Exception)
                {
                    TempData["msg"] = "<script>alert('אירעה תקלה בהוספת הנושא');</script>";
                    return(View());
                }
            }
            else
            {
                TempData["msg"] = "<script>alert('הנושא המבוקש כבר קיים');</script>";
                return(View());
            }

            SchoolClass schoolClass = GetClass(Session["CurrentClass"].ToString());

            InitializeClassView(schoolClass);

            TempData["msg"] = "<script>alert('הנושא נוסף בהצלחה');</script>";
            return(View("ClassView"));
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            ISchoolClassService schoolClassService = DependencyResolver.Current.GetService <ISchoolClassService>();

            bool letterExists = schoolClassService
                                .All()
                                .Any(
                sc => sc.ClassLetter == this.ClassLetter &&
                sc.ClassNumber == this.ClassNumber);

            if (letterExists)
            {
                yield return(new ValidationResult(
                                 "There is already another class with the same letter in this grade."));
            }
        }
Пример #3
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            ISchoolClassService schoolClassService = DependencyResolver.Current.GetService <ISchoolClassService>();

            var currentGradeAcademicYearId = schoolClassService.GetById(this.Id).Grade.AcademicYearId;

            bool letterExists = schoolClassService
                                .All()
                                .Any(
                sc => sc.ClassLetter == this.ClassLetter &&
                sc.Id != this.Id && sc.Grade.GradeYear == this.GradeYear &&
                sc.Grade.AcademicYearId == currentGradeAcademicYearId);

            if (letterExists)
            {
                yield return(new ValidationResult(
                                 "There is already another class with the same letter in this grade."));
            }
        }
Пример #4
0
        // GET: Students
        public ActionResult Index()
        {
            try
            {
                string userid = User.Identity.GetUserId();

                foreach (var std in _studentService.All().Include(x => x.Homeworks.Select(t => t.Text)))
                {
                    if (std.ApplicationUserId.Equals(userid))
                    {
                        student = std;
                        break;
                    }
                }


                Session["StudentName"] = student.Name;
                string note = "";

                if (student.notifyForNewHomework == true)
                {
                    student.notifyForNewHomework = false;
                    note = "קיימים שיעורי בית חדשים שעלייך להשלים.";
                    _studentService.Update(student);
                }

                if (student.notifyForNewGrade == true)
                {
                    student.notifyForNewGrade = false;
                    note = note + "\n קיבלת ציון חדש על שיעורי בית שהגשת.";
                    _studentService.Update(student);
                }

                Session["Notification"] = note;


                foreach (var sch_cls in _schoolClassService.All())
                {
                    if (sch_cls.Id.Equals(student.SchoolClass.Id))
                    {
                        schoolClass = sch_cls;
                        break;
                    }
                }

                schoolClassGuid = schoolClass.Id;

                ViewBag.Title = "בחר נושא";

                List <Subject> subjects = new List <Subject>();



                Session["SchoolClassID"] = schoolClass.Id.ToString();

                List <Guid> subjectsIDList = new List <Guid>();
                List <Tuple <string, string, Text> > tmpTexts = new List <Tuple <string, string, Text> >();
                subjects = schoolClass.Subjects.ToList();

                foreach (var hw in student.Homeworks)
                {
                    if (subjects.Contains(hw.Text.Subject))
                    {
                        subjectsIDList.Add(hw.Text.Subject_Id);
                        Tuple <string, string, Text> t = new Tuple <string, string, Text>(hw.Created_By.Name, hw.Deadline.ToString(), hw.Text);
                        tmpTexts.Add(t);
                    }
                }

                SubjectsNotificationsViewModel model = new SubjectsNotificationsViewModel();
                model.Subjects       = subjects;
                model.subjectsIDList = subjectsIDList;
                model.tmpTexts       = tmpTexts;
                return(View("Subjects", model));
            }
            catch (Exception e)
            {
                // RedirectToAction();
                return(RedirectToAction("LogIn", "Account", new { area = "Students" }));
            }
        }