public async Task <Announcement> CreateAnnouncement(Announcement tempAnnouncement) { _classDbContext.Add(tempAnnouncement); await _classDbContext.SaveChangesAsync(); return(tempAnnouncement); }
// Register new User // Takes a user object, checks if it the email is unique and adds to database. // Returns the newUserObject with an id field if add was successful otherwise the user object is returned unchanged. public async Task <User> AddNewUser(User newUser) { // Check if email is already in use User checkUnique = _classDbContext.Users .Where(u => u.Email == newUser.Email) .FirstOrDefault <User>(); if (checkUnique == null) { //Hash password newUser.Password = HashPassword("strivesalt", newUser.Password); // Email is unique add to database _classDbContext.Add(newUser); await _classDbContext.SaveChangesAsync(); // Update the newUser object so it includes the ID newUser = _classDbContext.Users .Where(u => u.Email == newUser.Email) .FirstOrDefault <User>(); } else { throw new Exception("User already exists"); } return(newUser); }
public async Task <Grade> SubmitAssignment(Grade tempGrade) { //gradeDB = ConvertoDBModel(tempGrade); var grade = _classDbContext.Add(tempGrade); await _classDbContext.SaveChangesAsync(); return(tempGrade); }
public async Task <IActionResult> Create([Bind("AssessmentId,Name,Date,Points")] Assessment assessment) { if (ModelState.IsValid) { _context.Add(assessment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(assessment)); }
//Takes a assignment object and enters it into the database and returns an object public async Task <Assignment> AddNewAssignment(Assignment newAssignment) { // Check if course number exists Course course = (from c in _classDbContext.Courses where c.CourseID == newAssignment.CourseID select c).FirstOrDefault <Course>(); if (course != null && course.CourseID == newAssignment.CourseID) { var addedAssignment = _classDbContext.Add(newAssignment); await _classDbContext.SaveChangesAsync(); return(newAssignment); } else { return(null); } }