public async Task <IHttpActionResult> PutStudent(string id, Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.Id) { return(BadRequest()); } db.Entry(student).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <ActionResult> Create([Bind(Include = "CourseId,DepartmentId,CourseCode,CourseName,CourseDescription,ExpectedTime")] Course course) { if (ModelState.IsValid) { db.Courses.Add(course); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "DepartmentCode", course.DepartmentId); return(View(course)); }
public async Task <int> AddGrade(List <Grade> objGrade) { try { await _lmsDbContext.Grade.AddRangeAsync(objGrade); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> AddTeacherSubject(TeacherSubject objTeacherSubject) { try { await _lmsDbContext.TeacherSubject.AddAsync(objTeacherSubject); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> AddStudentClass(StudentClass objStudent) { try { await _lmsDbContext.StudentClass.AddAsync(objStudent); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> AddClassSection(ClassSection objClassSection) { try { await _lmsDbContext.ClassSection.AddAsync(objClassSection); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> AddLecture(Lecture objLecture) { try { await _lmsDbContext.Lecture.AddAsync(objLecture); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> AddAnnouncement(Announcement objAnnouncement) { try { await _lmsDbContext.Announcement.AddAsync(objAnnouncement); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { // _logger.LogError($"The message is {ex.Message}. " + $"Stack trace is {ex.StackTrace}"); return(-1); } }
public async Task <int> DeleteStudent(int id) { try { var deleteStudent = await GetStudentById(id); _lmsDbContext.Student.Remove(deleteStudent); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <int> DeleteTeacher(int id) { try { var deleteTeacher = await GetTeacherById(id); _lmsDbContext.Teacher.Remove(deleteTeacher); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (System.Exception ex) { // _logger.LogError($"The message is {ex.Message}. " + $"Stack trace is {ex.StackTrace}"); return(-1); } }
public async Task <int> AddTeacherTestDetail(TestDetail objTestDetail) { try { await _lmsDbContext.TestDetail.AddAsync(objTestDetail); await _lmsDbContext.SaveChangesAsync(); return(1); } catch (Exception ex) { return(-1); } }
public async Task <ActionResult> Create([FromBody] Course course) { using (var transaction = db.Database.BeginTransaction()) { try { if (await db.Course.AnyAsync(c => c.CourseName == course.CourseName)) { // Note: This could be enforced by the SQL database by catching // exceptions thrown via the uniqueness constraint on the // courseName column when attempting to insert a course by the // same name. return(BadRequest("Course names must be unique.")); } else { await db.AddAsync(course); await db.SaveChangesAsync(); } transaction.Commit(); return(Ok(new { course.CourseId, course.CourseName, course.CreditHours, course.TeacherId })); } catch (Exception) { // TODO: Provide a meaningful message if possible. return(BadRequest()); } } }
public async Task <ActionResult <object> > Delete(long id) { // TODO: See the comments in CoursesController // regarding transactions. var teacher = await db.User .Where(u => u.UserId == id && u.Role == "Teacher") .FirstOrDefaultAsync(); if (teacher == null) { return(NotFound()); } db.User.Remove(teacher); await db.SaveChangesAsync(); return(new { teacher.UserId, Name = $"{teacher.FirstName} {teacher.LastName}", teacher.DateOfBirth }); }