Ejemplo n.º 1
0
        public IActionResult Info(int id, [FromForm] SubjectInfoBindingModel subjectInfo)
        {
            SubjectInfoDto subjectInfoDto = Mapper.Map <SubjectInfoDto>(subjectInfo);

            ServiceResult serviceResult = SubjectService.UpdateSubjectInfo(subjectInfoDto, id);

            if (serviceResult.Result == Result.Error)
            {
                foreach (var error in serviceResult.Errors)
                {
                    ModelState.AddModelError(error.Key, error.Message);
                }

                if (!ModelState.IsValid)
                {
                    var subjectInfoViewModel = new SubjectInfoViewModel(subjectInfo, id);
                    return(View(subjectInfoViewModel));
                }
            }
            else if (serviceResult.Result == Result.NotFound)
            {
                return(NotFound());
            }

            int subjectId = serviceResult.Id;

            return(RedirectToSubject(subjectId));
        }
Ejemplo n.º 2
0
        public IActionResult Info(int id)
        {
            SubjectInfoDto subjectInfoDto = SubjectService.GetSubjectInfo(id);

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

            SubjectInfoBindingModel subjectInfo = Mapper.Map <SubjectInfoBindingModel>(subjectInfoDto);
            var subjectInfoViewModel            = new SubjectInfoViewModel(subjectInfo, id);

            return(View(subjectInfoViewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> IndexTeacher(int subjectId)
        {
            Teacher teacher = await _authentication.GetCurrentTeacherAsync();

            if (!_subjectService.DoesSubjectBelongsToTeacher(subjectId, teacher.Id))
            {
                return(RedirectToAction("Profile", "Teacher"));
            }

            Subject subject = _databaseWorker.GetSubjectById(subjectId);
            IEnumerable <Models.Task> tasks = _taskService.GetTasksRelatedToSubject(subject);

            SubjectInfoViewModel model = new SubjectInfoViewModel {
                Subject = subject, Tasks = tasks
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> IndexStudent(int subjectId)
        {
            Student student = await _authentication.GetCurrentStudentAsync();

            if (!_subjectService.DoesSubjectBelongsToStudent(subjectId, student.Id))
            {
                return(RedirectToAction("Profile", "Student"));
            }

            Subject subject = _databaseWorker.GetSubjectById(subjectId);

            // should be remade

            IEnumerable <Models.Task> tasks = _taskService.GetTasksRelatedToSubject(subject);
            SubjectInfoViewModel      model = new SubjectInfoViewModel {
                Subject = subject, Tasks = tasks
            };

            return(View(model));
        }
        public IActionResult Edit(SubjectInfoViewModel subject, string id)
        {
            int subjectId   = this.GetSubjectIdFromString(id);
            int currentPage = this.GetPagesCountFromString(id);

            subject.Id = subjectId.ToString();

            if (!this.ModelState.IsValid)
            {
                return(this.View(subject));
            }

            using (this.db)
            {
                var teacherToEdit = this.subjectsService.GetById(subjectId);

                teacherToEdit.Name = subject.Name;

                this.db.SaveChanges();
                return(this.RedirectToAction("AllSubjects", new { page = currentPage }));
            }
        }