public async Task InsertNote(int userId, AddStudentNoteViewModel model) { const string sql = @" INSERT INTO [dbo].[StudentNotes] ([StudentId], [CreatedBy], [EntryDate], [Note]) VALUES (@StudentId, @CreatedBy, @EntryDate, @Note)"; try { await UnitOfWork.Context().ExecuteAsync(sql, new { StudentId = model.StudentId, CreatedBy = userId, EntryDate = DateTime.Now.ToUniversalTime(), Note = model.Note.Trim() }); } catch (Exception e) { e.Data["SQL"] = sql; ErrorStore.LogException(e, HttpContext.Current); throw e; } }
public ActionResult AddStudentNote(int?studentId, int?subjectId) { if (!subjectId.HasValue || !studentId.HasValue) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var subject = this.context.Subjects.Find(subjectId.Value); var student = this.context.Students.Find(studentId.Value); if (subject == null || student == null) { return(this.HttpNotFound()); } var viewModel = new AddStudentNoteViewModel { StudentId = student.Id, StudentName = $"{student.LastName} {student.FirstName}", SubjectId = subject.Id, SubjectName = subject.Name }; return(this.View(viewModel)); }
public ActionResult AddStudentNote(AddStudentNoteViewModel viewModel) { var subject = this.context.Subjects.Find(viewModel.SubjectId); var student = this.context.Students.Find(viewModel.StudentId); if (subject == null || student == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (!this.ModelState.IsValid) { viewModel.StudentName = $"{student.LastName} {student.FirstName}"; viewModel.SubjectName = subject.Name; return(this.View(viewModel)); } var note = this.context.Notes.Create(); note.Value = viewModel.Value; note.Comment = viewModel.Comment; note.Date = DateTime.Now; note.Student = student; note.Subject = subject; this.context.Notes.Add(note); this.context.SaveChanges(); return(this.RedirectToAction("Subject", "Teacher", new { id = subject.Id })); }
public async Task Add(AddStudentNoteViewModel model) { if (ModelState.IsValid) { await StudentNoteService.InsertNote((Session["User"] as UserModel).Id, model, HttpContext.Request.UserHostAddress); } }
public async Task InsertNote(int userId, AddStudentNoteViewModel model, string remoteIp) { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { await StudentNoteRepository.InsertNote(userId, model); await EventLogService.AddStudentEvent(userId, model.StudentId, EventLogTypes.AddStudentNote, remoteIp); scope.Complete(); } }