Esempio n. 1
0
        //Takes a course object and enters it into the database and returns an object with the CourseID
        public async Task <Course> AddNewCourse(Course newCourse)
        {
            var addedCourse = _classDbContext.Add(newCourse);
            await _classDbContext.SaveChangesAsync();

            return(newCourse);
        }
Esempio n. 2
0
        // 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);
        }
Esempio n. 3
0
        public async Task <Assignment> UpdateAssignment(Assignment assignment)
        {
            _classDbContext.Assignments.Update(assignment);
            await _classDbContext.SaveChangesAsync();

            return(assignment);
        }
Esempio n. 4
0
        public async Task <Grade> SubmitAssignment(Grade tempGrade)
        {
            //gradeDB = ConvertoDBModel(tempGrade);
            var grade = _classDbContext.Add(tempGrade);
            await _classDbContext.SaveChangesAsync();

            return(tempGrade);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public async Task <Announcement> CreateAnnouncement(Announcement tempAnnouncement)
        {
            _classDbContext.Add(tempAnnouncement);
            await _classDbContext.SaveChangesAsync();

            return(tempAnnouncement);
        }
        public JsonResult Update(string strEmployee)
        {
            //Convert
            var data  = JsonConvert.DeserializeObject <Employee>(strEmployee);
            var model = context.Employees.Find(data.Id);

            model.Age = data.Age;
            context.SaveChangesAsync();
            return(Json(new
            {
                status = true
            }));
        }
Esempio n. 8
0
        public async Task CheckAssignmentAddingAndRetriving()
        {
            Assignment testAssignment = new Assignment();

            //testAssignment.AssignmentID = 999;
            testAssignment.CourseID              = 1;
            testAssignment.DueDate               = DateTime.Now;
            testAssignment.AssignmentTitle       = "testing";
            testAssignment.AssignmentDescription = "testDescription";
            testAssignment.AssignmentType        = "test";
            testAssignment.TotalPossible         = 10;

            var returnedAssignment = await _assignmentService.AddNewAssignment(testAssignment);

            List <Assignment> assignmentList = (_assignmentService.GetAssigmentByCourseID(1));

            Assignment checkAssignment = null;

            for (int i = 0; i < assignmentList.Count; i++)
            {
                if (assignmentList[i].AssignmentID == returnedAssignment.AssignmentID)
                {
                    checkAssignment = assignmentList[i];
                    break;
                }
            }

            Assert.IsTrue(testAssignment.CourseID == checkAssignment.CourseID &&
                          testAssignment.AssignmentID == checkAssignment.AssignmentID &&
                          testAssignment.DueDate == checkAssignment.DueDate &&
                          testAssignment.AssignmentTitle == checkAssignment.AssignmentTitle &&
                          testAssignment.AssignmentDescription == checkAssignment.AssignmentDescription &&
                          testAssignment.AssignmentType == checkAssignment.AssignmentType &&
                          testAssignment.TotalPossible == checkAssignment.TotalPossible);

            _dbContext.Remove(testAssignment);
            await _dbContext.SaveChangesAsync();
        }