public async Task <JsonResult> AssignAsync(Guid studentId, Guid semesterId)
        {
            var studentSemester = new StudentSemesterViewModel
            {
                StudentId  = studentId,
                SemesterId = semesterId
            };
            var result = await _studentService.AddStudentSemesterAsync(studentSemester);

            return(new JsonResult(result));
        }
Ejemplo n.º 2
0
        public IActionResult AddStudentSemester(int id)
        {
            var student              = context.Students.Find(id);
            var semesters            = context.Semesters.ToList();
            var studentSemesterModel = new StudentSemesterViewModel
            {
                FirstName = student.FirstName,
                LastName  = student.LastName,
                Semesters = semesters,
            };

            return(View(studentSemesterModel));
        }
Ejemplo n.º 3
0
        public async Task <StudentSemesterViewModel> AddStudentSemesterAsync(StudentSemesterViewModel studentSemester)
        {
            try
            {
                var jsonPayload = JsonConvert.SerializeObject(studentSemester);
                var body        = new StringContent(jsonPayload, Encoding.UTF8, "application/json");
                var response    = await Client.PostAsync("api/student/semester", body);

                response.EnsureSuccessStatusCode();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(studentSemester);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> AddStudentSemester(string submit, StudentSemesterViewModel viewModel)
        {
            var studentSemester = new StudentSemester
            {
                StudentId  = viewModel.Id,
                SemesterId = viewModel.SemesterId,
            };

            if (submit == "Add")
            {
                try
                {
                    await context.AddAsync(studentSemester);

                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception)
                {
                    if (viewModel.SemesterId == 0)
                    {
                        return(NotFound("Please select a semester!"));
                    }
                    var semester = context.Semesters.
                                   Where(x => x.Id == viewModel.SemesterId)
                                   .Select(s => s.SemesterName)
                                   .FirstOrDefault();

                    return(NotFound($"This student has {semester}"));
                }
            }

            try
            {
                context.Remove(studentSemester);
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                return(NotFound("The student doesn`t have such semester!"));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Details(string id)
        {
            var model = new StudentDetailViewModel();
            var user  = UserManager.FindById(id);

            model.User     = user;
            model.Students = Db.Students.Where(x => x.UserId.Equals(user.Id)).OrderByDescending(x => x.Created).ToList();
            model.Student  = model.Students.FirstOrDefault();

            var semester = SemesterService.GetSemester(DateTime.Today);
            var org      = GetMyOrganisation();

            var allCourses = Db.Activities.OfType <Course>().Where(x => x.Occurrence.Subscriptions.Any(s => s.UserId.Equals(user.Id))).ToList();

            foreach (var course in allCourses)
            {
                foreach (var semesterGroup in course.SemesterGroups)
                {
                    var semModel = model.Semester.FirstOrDefault(x => x.Semester.Id == semesterGroup.Semester.Id);
                    if (semModel == null)
                    {
                        semModel = new StudentSemesterViewModel
                        {
                            Semester = semesterGroup.Semester
                        };

                        model.Semester.Add(semModel);
                    }

                    if (!semModel.Courses.Contains(course))
                    {
                        semModel.Courses.Add(course);
                    }
                }
            }

            ViewBag.UserRight = GetUserRight();

            return(View(model));
        }