public JsonResult AddLesson(AddLessonFormData addLessonFormData) { if (ModelState.IsValid) { var response = educationComplexManager.AddLesson(addLessonFormData); if (response.IsSuccess) { return(Json(new { IsSuccess = true })); } else { return(Json(new { IsSuccess = false, Error = response.Explanation })); } } else { string message = string.Empty; foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { message += error.ErrorMessage + "\n"; } } return(Json(new { IsSuccess = false, Error = message })); } }
public IHttpActionResult AddLesson([FromBody] AddLessonFormData addLessonFormData) { if (ModelState.IsValid) { var response = educationComplexManager.AddLesson(addLessonFormData); if (response.IsSuccess) { return(Ok()); } else { return(BadRequest(response.Explanation)); } } else { string message = string.Empty; foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { message += error.ErrorMessage + "\n"; } } return(BadRequest(message)); } }
public TransactionObject AddLesson(AddLessonFormData alFormData) { TransactionObject response = new TransactionObject(); try { Education education = educationManager.GetEducation(alFormData.StudentID, alFormData.LessonID); Student selectedStudent = studentManager.GetStudent(alFormData.StudentID); Lesson selectedLesson = lessonManager.GetLesson(alFormData.LessonID); if (education != null) { Period currentPeriod = periodManager.GetPeriod(selectedLesson.Period.Year, selectedLesson.Period.Semester); Note note = new Note { ResultPoint = alFormData.Result, Description = alFormData.Description, EffectRate = alFormData.Effect, Education = education }; note.Education = education; education.Notes.Add(note); noteManager.AddNote(note); } else { education = new Education(); education.Student = selectedStudent; selectedStudent.Educations.Add(education); education.Lesson = selectedLesson; selectedLesson.Educations.Add(education); Note note = new Note { ResultPoint = alFormData.Result, Description = alFormData.Description, EffectRate = alFormData.Effect, Education = education }; education.Notes.Add(note); note.Education = education; noteManager.AddNote(note); educationManager.AddEducation(education); } double avg = 0; education.Notes.ForEach(note => avg += (note.EffectRate / 100) * note.ResultPoint); education.Average = avg; uow.Save(); response.IsSuccess = true; } catch (Exception ex) { response.IsSuccess = false; response.Explanation = base.GetExceptionMessage(ex); } return(response); }