Exemple #1
0
        public async Task <IActionResult> CreateProject([FromBody] ProjectResource projectResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var project = mapper.Map <ProjectResource, Project> (projectResource);

            var major = await majorRepository.GetMajor(projectResource.MajorId);

            project.Major = major;

            var lecturer = await lecturerRepository.GetLecturer(projectResource.LecturerId);

            project.Lecturer = lecturer;

            projectRepository.AddProject(project);

            projectRepository.UpdateGroups(project, projectResource);
            projectRepository.UpdateTagProjects(project, projectResource);

            //Add categories into projects
            var categories = GetCategoriesFromDescription(projectResource.Description);
            await projectRepository.UpdateCategories(project, categories);

            await unitOfWork.Complete();

            project = await projectRepository.GetProject(project.ProjectId);

            var result = mapper.Map <Project, ProjectResource> (project);

            return(Ok(result));
        }
        public async Task <IActionResult> CreateboardEnrollment([FromBody] BoardEnrollmentResource boardEnrollmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var boardEnrollment = mapper.Map <BoardEnrollmentResource, BoardEnrollment>(boardEnrollmentResource);

            boardEnrollment.Lecturer = await lecturerRepository.GetLecturer(boardEnrollmentResource.LecturerID);

            boardEnrollment.Board = await boardRepository.GetBoard(boardEnrollmentResource.BoardID);

            if (boardEnrollment.Score != null)
            {
                boardEnrollment.isMarked = true;
            }

            boardEnrollmentRepository.UpdateRecommendations(boardEnrollment, boardEnrollmentResource);

            boardEnrollmentRepository.AddBoardEnrollment(boardEnrollment);

            await unitOfWork.Complete();

            boardEnrollment = await boardEnrollmentRepository.GetBoardEnrollment(boardEnrollment.BoardEnrollmentId);

            var result = mapper.Map <BoardEnrollment, BoardEnrollmentResource>(boardEnrollment);

            return(Ok(result));
        }
Exemple #3
0
        public async Task <IActionResult> GetLecturer(int id)
        {
            var lecturer = await repository.GetLecturer(id);

            if (lecturer == null)
            {
                return(NotFound());
            }

            var lecturerResource = mapper.Map <Lecturer, LecturerResource>(lecturer);

            return(Ok(lecturerResource));
        }
Exemple #4
0
        public async Task <IActionResult> CreateLecturer([FromBody] LecturerResource lecturerResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var lecturer = mapper.Map <LecturerResource, Lecturer>(lecturerResource);

            var major = await majorRepository.GetMajor(lecturerResource.MajorId);

            lecturer.Major = major;

            var user = new ApplicationUser
            {
                FullName = lecturer.Name,
                Major    = lecturer.Major.MajorName,
                Avatar   = "/assets/images/user.png",
                Email    = lecturer.Email,
                UserName = lecturer.Email
            };

            if (RoleExists("Lecturer"))
            {
                //Check Student Existence
                if (!LecturerExists(user.Email))
                {
                    var password = "******"; // Password Default
                    await userManager.CreateAsync(user, password);

                    await userManager.AddToRoleAsync(user, "Lecturer");
                }
                else
                {
                    ModelState.AddModelError("", "Email is registered");
                }
            }
            else
            {
                ModelState.AddModelError("", "'Lecturer' role does not exist");
            }
            lecturerRepository.AddLecturer(lecturer);
            await unitOfWork.Complete();

            lecturer = await lecturerRepository.GetLecturer(lecturer.LecturerId);

            var result = mapper.Map <Lecturer, LecturerResource>(lecturer);

            return(Ok(result));
        }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                _logger.LogInformation("User" + model.UserId.Trim().Length);
                if (model.UserId.Trim().StartsWith("s", StringComparison.Ordinal) && model.UserId.Trim().Length - 1 == 5)
                {
                    await LoginTask(model, returnUrl);

                    Lecturer lecturer = _lecturerRepository.GetLecturer(model.UserId.Substring(1, model.UserId.Length - 1));
                    HttpContext.Session.SetInt32(LID, lecturer.lecturer_id);
                    HttpContext.Session.SetInt32(CID, lecturer.course_id);
                    HttpContext.Session.SetBoolean(isAdmin, lecturer.admin);
                }
                else if (model.UserId.Trim().StartsWith("p", StringComparison.Ordinal) && model.UserId.Trim().Length - 1 == 7)
                {
                    await LoginTask(model, returnUrl);


                    Student student = _studentRepository.GetStudent(model.UserId.Substring(1, model.UserId.Length - 1));
                    HttpContext.Session.SetInt32(SID, student.student_id);
                    HttpContext.Session.SetInt32(groupId, student.group_id ?? default(int));
                    HttpContext.Session.SetString(groupRole, student.group_role == null ? "" : student.group_role);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #6
0
        public async Task <IActionResult> CreateEnrollment([FromBody] EnrollmentResource enrollmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var enrollment = mapper.Map <EnrollmentResource, Enrollment>(enrollmentResource);
            var student    = await studentRepository.GetStudentByEmail(enrollmentResource.StudentEmail);

            enrollment.Student = student;

            var lecturer = await lecturerRepository.GetLecturer(enrollmentResource.LecturerId);

            enrollment.Lecturer = lecturer;
            SendMail(student.Name, lecturer.Email);
            //case: enrollment's type and project's type is different and the student has been already in group
            var group = await groupRepository.GetGroup(enrollmentResource.GroupId);

            if (group != null && group.Project.Type != enrollmentResource.Type)
            {
                ModelState.AddModelError("Error", "Enrollment's type and Project Type of Group are not the same.");
                return(BadRequest(ModelState));
            }
            else if (group != null && !groupRepository.CheckEnrollment(group, enrollment))
            {
                ModelState.AddModelError("Warning", "This group already has this student.");
                return(BadRequest(ModelState));
            }
            else
            {
                enrollment.Group = group;
            }

            var quarter = await quarterRepository.GetQuarter(enrollmentResource.QuarterId);

            enrollment.Quarter = quarter;

            enrollmentRepository.AddEnrollment(enrollment);
            await unitOfWork.Complete();

            enrollment = await enrollmentRepository.GetEnrollment(enrollment.EnrollmentId);

            var result = mapper.Map <Enrollment, EnrollmentResource>(enrollment);

            return(Ok(result));
        }
        public ActionResult Index()
        {
            HttpContext.Session.SetBoolean("IndexStudent", false);
            HttpContext.Session.SetBoolean("IndexUser", false);
            Lecturer lecturer = _lecturerctx.GetLecturer(User.Identity.Name.ToString().Substring(1, User.Identity.Name.ToString().Length - 1));
            int      courseId = HttpContext.Session.GetInt32(CID) ?? default(int);

            if (User.IsInRole("Admin"))
            {
                IEnumerable <ProposalViewModel> proposals = _proposalctx.Get(lecturer);
                HttpContext.Session.SetBoolean("IndexExternal", true);
                return(View("~/Views/_Admin/Proposal/Index.cshtml", proposals));
            }
            else
            {
                Debug.WriteLine(lecturer.lecturer_id);
                IEnumerable <ProposalViewModel> proposals = _proposalctx.GetForLecturer(lecturer);

                return(View("~/Views/_Lecturer/Proposal/Index.cshtml", proposals));
            }
        }
        /// <summary>
        /// This resets the password link for the user
        /// Enable user to set new password
        /// userId is either admin/ staff id
        /// </summary>
        public async Task ResetUserPassword(string userId)
        {
            int userType = GetUserType(userId);

            if (userType == 1)
            {
                Lecturer lecturer = ctx.GetLecturer(userId);
                if (lecturer != null)
                {
                    await UpdateUserPasswordLink(lecturer.email_address, 1, userId);
                }
            }

            if (userType == 3)
            {
                Student student = studCtx.GetStudent(userId);
                if (student != null)
                {
                    await UpdateUserPasswordLink(student.email_address, 3, userId);
                }
            }
        }
Exemple #9
0
        public async Task <IActionResult> UpdateGroup(int id, [FromBody] GroupResource groupResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var group = await groupRepository.GetGroup(id);

            if (group == null)
            {
                return(NotFound());
            }

            mapper.Map <GroupResource, Group>(groupResource, group);

            group.Lecturer = await lecturerRepository.GetLecturer(groupResource.LecturerId.Value);

            if (groupResource.ProjectId == null)
            {
                var otherProject = mapper.Map <ProjectResource, Project>(groupResource.OtherProject);
                group.Project = otherProject;
            }
            else
            {
                group.Project = await projectRepository.GetProject(groupResource.ProjectId.Value);
            }

            var major = await majorRepository.GetMajor(groupResource.MajorId);

            group.Major = major;

            var quarter = await quarterRepository.GetQuarter(groupResource.QuarterId);

            group.Quarter = quarter;

            groupRepository.UpdateEnrollments(group, groupResource);
            groupRepository.UpdateUploadedFiles(group, groupResource);

            await unitOfWork.Complete();

            //foreach (var enrollmentResource in groupResource.Enrollments)
            //{
            //    var enrollment = await enrollmentRepository.GetEnrollment(enrollmentResource.EnrollmentId);
            //    //case: enrollment's type and project's type is different and the student has been already in group

            //    if (group != null && group.Project.Type != enrollment.Type)
            //    {
            //        ModelState.AddModelError("Error", "Enrollment's type and Project Type of Group are not the same.");
            //        return BadRequest(ModelState);
            //    }
            //    else if (group != null && !groupRepository.CheckEnrollment(group, enrollment))
            //    {
            //        ModelState.AddModelError("Warning", "This group already has this student.");
            //        return BadRequest(ModelState);
            //    }
            //    else
            //    {
            //        enrollment.Group = group;
            //        group.Enrollments.Add(enrollment);
            //        await unitOfWork.Complete();
            //    }

            //}

            var result = mapper.Map <Group, GroupResource>(group);

            return(Ok(result));
        }