Exemple #1
0
        public async Task CreateAssignment(CourseNameViewModel courseModel)
        {
            foreach (var user in courseModel.Users.Where(u => u.Checked))
            {
                var userAlreadyHasAssignment = this.context.Users
                                               .First(u => u.Id == user.UserId)
                                               .Assignments
                                               .Any(c => c.CourseId == courseModel.CourseId);

                if (userAlreadyHasAssignment)
                {
                    continue;
                }

                var assignment = new Assignment();
                assignment.DateOfAssignment = DateTime.Now;
                assignment.State            = AssignmentState.Pending;
                assignment.DueDate          = user.DueDate;
                assignment.CourseId         = courseModel.CourseId;
                assignment.UserId           = user.UserId;

                if (user.Type == false)
                {
                    assignment.Type = "Optional";
                }
                else
                {
                    assignment.Type = "Mandatory";
                }

                this.context.Assignments.Add(assignment);
            }

            await SaveToDb();
        }
        public bool EditCourseNameAndTypeName(CourseNameViewModel course)
        {
            bool flag = true;

            try
            {
                var DbCourse = db.Course.Where(x => x.CourseID == course.CourseID).Select(a => a);
                foreach (var i in DbCourse)
                {
                    i.CourseName = course.CourseName;
                }
                ;
                var DbType = db.TypeInfo.Where(x => x.TID == course.TID).Select(a => a);
                foreach (var i in DbType)
                {
                    i.TypeName = course.TypeName;
                }
                db.SubmitChanges();
            }
            catch (Exception)
            {
                flag = false;
            }
            return(flag);
        }
 public JsonResult AddOneCourse(CourseNameViewModel course)
 {
     if (_course.AddOneCourse(course))
     {
         return(Json(new { row = course, flag = true }));
     }
     return(Json(new { msg = "错误代码:没有", flag = false }));
 }
 public JsonResult DeleteCourse(CourseNameViewModel course)
 {
     if (_course.DeleteCourse(course))
     {
         return(Json(true));
     }
     return(Json(false));
 }
 public JsonResult EditCourse(CourseNameViewModel course)
 {
     if (_course.EditCourseNameAndTypeName(course))
     {
         return(Json(true));
     }
     return(Json(false));
 }
Exemple #6
0
        public async Task <ActionResult> AssignTo(CourseNameViewModel courseModel)
        {
            if (this.ModelState.IsValid)
            {
                await assignmentService.CreateAssignment(courseModel);

                return(this.RedirectToAction("Home", "Admin"));
            }

            return(this.View(courseModel));
        }
Exemple #7
0
        public void RedirectToAction()
        {
            // Assert
            var courseModel = new CourseNameViewModel();
            var serviceMock = new Mock <IAssignmentService>();

            var userStore       = new Mock <IUserStore <ApplicationUser> >();
            var userManagerMock = new Mock <ApplicationUserManager>(userStore.Object);

            var controller = new AssignmentController(serviceMock.Object, userManagerMock.Object);

            // Act && Assert
            controller
            .WithCallTo(c => c.AssignTo(courseModel))
            .ShouldRedirectTo <AdminController>(r => r.Home());
        }
        public bool DeleteCourse(CourseNameViewModel course)
        {
            bool flag = true;

            try
            {
                var Delete = db.Course.Where(x => x.CourseID == course.CourseID).FirstOrDefault();
                db.Course.DeleteOnSubmit(Delete);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }
            return(flag);
        }
        public bool AddOneCourse(CourseNameViewModel course)
        {
            bool flag = true;

            try
            {
                db.Course.InsertOnSubmit(new Course
                {
                    CourseID   = Convert.ToDouble(course.CourseID),
                    CourseName = course.CourseName,
                    TID        = course.TID
                });
                db.SubmitChanges();
            }
            catch (Exception)
            {
                flag = false;
            }
            return(flag);
        }
Exemple #10
0
        public async Task <ActionResult> AssignTo(int courseId)
        {
            var chosenCourse = await assignmentService.GetById(courseId);

            var model = new CourseNameViewModel();

            var allUsers = this.userManager.Users
                           .Select(u => new UserAssignedViewModel()
            {
                Username = u.UserName,
                UserId   = u.Id,
                Checked  = false,
                Type     = false
            })
                           .ToList();

            model.Users    = allUsers;
            model.Name     = chosenCourse.Name;
            model.CourseId = courseId;

            return(this.View(model));
        }