private void SubmitHomework(Text textForHomework, Teacher currentTeacher, Guid currentTeacherId, Guid currentTextId, DateTime?submissionDate, string homeworkTitle, string homeworkDescription) { var questions = _fileManager.ParseQuestions(Server.MapPath("~/TemporaryFiles/Homeworks"), currentTeacherId, currentTextId); if (questions == null || questions.Count == 0) { TempData["msg"] = "<script>alert('יש להוסיף שאלות לשיעורי הבית');</script>"; return; } if (submissionDate == null) { TempData["msg"] = "<script>alert('לא הוכנס תאריך הגשה לשיעורי הבית');</script>"; return; } var homework = new Homework() { Text = textForHomework, Text_Id = currentTextId, Questions = questions, Deadline = (DateTime)submissionDate, Created_By = currentTeacher, Teacher_Id = currentTeacherId, Title = homeworkTitle, Description = homeworkDescription }; // Add Homework to relevant tables in DB: var currentClass = GetClass(Session["CurrentClass"].ToString()); var currentClassId = currentClass.Id; try { _classService.GetById(currentClassId).Homeworks.Add(homework); foreach (var student in _classService.GetById(currentClassId).Students) { student.Homeworks.Add(homework); } _homeworkService.Add(homework); } catch (Exception e) { TempData["msg"] = "<script>alert('אירעה תקלה בהוספת שיעורי הבית');</script>"; return; } _fileManager.ClearTemporaryQuestions(Server.MapPath("~/TemporaryFiles/Homeworks"), currentTeacherId, currentTextId); TempData.Clear(); TempData["msg"] = "<script>alert('שיעורי הבית נוספו בהצלחה, כעת התלמידים יוכלו לראות אותם');</script>"; }
public ActionResult RemoveStudentFromClass(Guid id, string username) { Student s = this.studentService.GetByUserName(username); SchoolClass sc = schoolClassService.GetById(id); MichtavaResult res = this.schoolClassService.RemoveStudentFromClass(s, sc); if (res is MichtavaFailure) { ModelState.AddModelError(string.Empty, res.Message); } return(RedirectToAction("Students", "SchoolClasses", new { id = sc.Id })); }
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.")); } }
public async Task <Fee> GenerateFee(Student student, FeeCycle cycle, School school) { var feesForStudent = await Get(x => x.StudentId == student.Id); var classForStudent = await _schoolClassService.GetById(student.ClassId); var allFeeForStudentExcludingCancelled = feesForStudent.Where(x => x.FeeStatus != FeeStatus.Cancelled).ToList(); var feesData = feesForStudent.Where(x => x.FeeCycleId == cycle.Id && x.StudentId == student.Id).ToList(); var singleExistingFee = feesData.FirstOrDefault(); if (feesData.Count() > 1) { singleExistingFee = feesData.OrderByDescending(x => x.CreatedAt).FirstOrDefault(); } if (singleExistingFee != null && singleExistingFee.FeeStatus == FeeStatus.Cancelled) { singleExistingFee = null; } var fee = new Fee(); if (singleExistingFee != null) { if (singleExistingFee.FeeStatus == FeeStatus.Approved || singleExistingFee.FeeStatus == FeeStatus.Paid || singleExistingFee.FeeStatus == FeeStatus.PartialPaid) { return(singleExistingFee); } fee = singleExistingFee; fee.Components = new Component[] { }; } else { fee.StudentId = student.Id; fee.FeeCycleId = cycle.Id; fee.SchoolId = school.Id; fee.Components = new Component[] { }; } fee.FeeStatus = FeeStatus.PendingApproval; fee.CancelledBy = null; fee.CancelledBy = null; var schoolFeeComponets = school.SchoolFeeComponents; var schoolComponentDict = schoolFeeComponets.ToDictionary(x => x.Id, x => x); if (student.FeeComponets.Length == 0) { var studentClassFeeComponent = await GetChildFeesComponents(cycle.SessionId, student); if (studentClassFeeComponent == null) { return(null); } if (studentClassFeeComponent.Length <= 0) { return(null); } foreach (var component in studentClassFeeComponent) { if (!schoolComponentDict.ContainsKey(component.SchoolFeeComponentId)) { continue; } var parent = schoolComponentDict[component.SchoolFeeComponentId]; if (parent.Periodicity == Periodicity.Monthly) { var toaddComp = new Component { ComponetId = component.SchoolFeeComponentId, Value = component.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } if (parent.Periodicity == Periodicity.OneTime) { var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && x.Components.Select(y => y.ComponetId).Contains(component.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = component.SchoolFeeComponentId, Value = component.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } if (parent.Periodicity == Periodicity.Yearly) { var allCycleForThisSession = school.FeeCycles.Where(x => x.SessionId == cycle.SessionId).Select(x => x.Id); var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && allCycleForThisSession.Contains(x.FeeCycleId) && x.Components.Select(y => y.ComponetId).Contains(component.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = component.SchoolFeeComponentId, Value = component.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } } } else { var studentFeeComponent = student.FeeComponets; foreach (var superComp in schoolFeeComponets) { var isExistingInStudent = studentFeeComponent.FirstOrDefault(x => x.SchoolFeeComponentId == superComp.Id); if (isExistingInStudent != null) { if (!schoolComponentDict.ContainsKey(isExistingInStudent.SchoolFeeComponentId)) { continue; } var parent = schoolComponentDict[isExistingInStudent.SchoolFeeComponentId]; if (parent.Periodicity == Periodicity.Monthly) { var toaddComp = new Component { ComponetId = isExistingInStudent.SchoolFeeComponentId, Value = isExistingInStudent.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } if (parent.Periodicity == Periodicity.OneTime) { var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && x.Components.Select(y => y.ComponetId) .Contains(isExistingInStudent.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = isExistingInStudent.SchoolFeeComponentId, Value = isExistingInStudent.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } if (parent.Periodicity == Periodicity.Yearly) { var allCycleForThisSession = school.FeeCycles.Where(x => x.SessionId == cycle.SessionId).Select(x => x.Id); var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && allCycleForThisSession.Contains(x.FeeCycleId) && x.Components.Select(y => y.ComponetId) .Contains(isExistingInStudent.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = isExistingInStudent.SchoolFeeComponentId, Value = isExistingInStudent.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } } else { var isExistingInClass = classForStudent.FeeComponets.FirstOrDefault(x => x.SchoolFeeComponentId == superComp.Id); if (isExistingInClass != null) { if (!schoolComponentDict.ContainsKey(isExistingInClass.SchoolFeeComponentId)) { continue; } var parent = schoolComponentDict[isExistingInClass.SchoolFeeComponentId]; if (parent.Periodicity == Periodicity.Monthly) { var toaddComp = new Component { ComponetId = isExistingInClass.SchoolFeeComponentId, Value = isExistingInClass.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } if (parent.Periodicity == Periodicity.OneTime) { var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && x.Components.Select(y => y.ComponetId) .Contains(isExistingInClass.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = isExistingInClass.SchoolFeeComponentId, Value = isExistingInClass.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } if (parent.Periodicity == Periodicity.Yearly) { var allCycleForThisSession = school.FeeCycles.Where(x => x.SessionId == cycle.SessionId).Select(x => x.Id); var already = allFeeForStudentExcludingCancelled.FirstOrDefault( x => x.Id != fee.Id && allCycleForThisSession.Contains(x.FeeCycleId) && x.Components.Select(y => y.ComponetId) .Contains(isExistingInClass.SchoolFeeComponentId)); if (already == null) { var toaddComp = new Component { ComponetId = isExistingInClass.SchoolFeeComponentId, Value = isExistingInClass.Value }; fee.Components = fee.Components != null ? fee.Components.Concat(new[] { toaddComp }).ToArray() : new[] { toaddComp }; } } } } } } if (fee.Id == ObjectId.Empty || fee.FeeStatus == FeeStatus.Cancelled) { await Add(fee); } else { await Update(fee); } return(fee); }