public IHttpActionResult ContactUsInsert(ContactUsViewModel model) { _contactUsService.ContactUsInsert(model.ToModel()); try { var htmlData = GetContactHtml(); string emailBody = string.Format(htmlData, model.Name, model.EmailAddress, model.PhoneNumber, model.Message); EmailSenders.SendEmail("*****@*****.**", "Contact Request", emailBody).Wait(); } catch { return(Json(new { message = "Some Error" })); } return(Json(new { message = "Save Successfully" })); }
public GradeDTO CreateGrade(string teacherId, GradeCreateAndEditDTO dto) { Teacher teacher = db.TeachersRepository.GetByID(teacherId); Student student = db.StudentsRepository.GetByID(dto.StudentId); SchoolSubject subject = db.SchoolSubjectsRepository.GetByID(dto.SchoolSubjectId); SchoolClass sc = db.SchoolClassesRepository.GetByID(student.SchoolClass.Id); if (teacher == null) { logger.Warn("Teacher with id {0} not found.", teacherId); throw new KeyNotFoundException("teacherId doesn't exist."); } if (student == null) { logger.Warn("Student with id {0} not found.", dto.StudentId); throw new KeyNotFoundException("dto.StudentId doesn't exist."); } if (subject == null) { logger.Warn("Subject with id {0} not found.", dto.SchoolSubjectId); throw new KeyNotFoundException("dto.SchoolSubjectId doesn't exist."); } if (!teacher.TeacherSchoolSubjects.Select(x => x.SchoolSubject).Any(y => y.Id == subject.Id)) { logger.Warn("Teacher {0} {1} (id: {2}) does not teach subject {3} (id: {4}). Cannot grade the student.", teacher.FirstName, teacher.LastName, teacher.Id, subject.Name, subject.Id); throw new Exception("Teacher doesn't teach the given subject."); //TODO 99: fix exceptions! } if (!teacher.TeacherSchoolSubjects.Any(x => x.SchoolClassTeacherSchoolSubjects.Any(y => y.SchoolClass.Id == sc.Id))) { logger.Warn("Teacher {0} {1} (id: {2}) doesn't teach the subject {3} (id: {4}) to student {5} {6} (id: {7}). Cannot grade the student.", teacher.FirstName, teacher.LastName, teacher.Id, subject.Name, subject.Id, student.FirstName, student.LastName, student.Id); throw new Exception("Teacher doesn't teach the subject to the given student"); } TeacherSchoolSubject tss = db.TeacherSchoolSubjectSRepository.Get() .Where(x => x.SchoolSubject.Id == subject.Id && x.Teacher.Id == teacher.Id).FirstOrDefault(); if (tss == null) { logger.Warn("TeacherSchoolSubject combination with teacherId {0} and subject id {1} not found.", teacher.Id, subject.Id); throw new KeyNotFoundException("Given TeacherSchoolSubject combination doesn't exist. Please make one."); } SchoolClassTeacherSchoolSubject sctss = db.SchoolClassTeacherSchoolSubjectRepository.Get() .Where(x => x.TeacherSchoolSubject.Id == tss.Id && x.SchoolClass.Id == sc.Id).FirstOrDefault(); if (sctss == null) { logger.Warn("SchoolClassTeacherSchoolSubject combination with schoolClassId {0} and teacherSchoolSubjectId {1} not found.", sc.Id, tss.Id); throw new KeyNotFoundException("Given SchoolClassTeacherSchoolSubject combination doesn't exist. Please make one."); } Grade grade = new Grade() { Value = dto.Value, DateOfGrading = DateTime.Now, SchoolClassTeacherSchoolSubject = sctss, Student = student }; logger.Info("Creating grade. teacherId: {0}, studentId: {1}, subjectId: {2}", teacher.Id, student.Id, subject.Id); db.GradesRepository.Insert(grade); db.Save(); string toEmail = student.Parent.Email; string parentName = student.Parent.FirstName + " " + student.Parent.LastName; string studentName = student.FirstName + " " + student.LastName; string date = grade.DateOfGrading.Day + "." + grade.DateOfGrading.Month + "." + grade.DateOfGrading.Year; string subjectName = subject.Name; int gradeValue = grade.Value; EmailSenders.EmailGradingEventToParent(toEmail, parentName, studentName, date, subjectName, gradeValue); return(GradeToGradeDTOConverters.GradeToGradeDTO(grade)); }