예제 #1
0
        public async Task Add(SubjectInputModel model)
        {
            Subject subject = model.To <Subject>();
            await repository.AddAsync(subject);

            await repository.SaveChangesAsync();
        }
        public async Task <IActionResult> Create(SubjectInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            await subjectService.Add(model);

            return(RedirectToAction(nameof(GetAll)));
        }
        public async Task <ActionResult <SubjectViewModel> > SaveSubject([FromBody] SubjectInputModel subjectInput)
        {
            Subject subject = _mapper.Map <Subject>(subjectInput);

            for (int i = 0; i < 3; ++i)
            {
                subject.Qualifications.Add(new Qualification {
                    Cort = i + 1
                });
            }

            dbContext.Subjects.Add(subject);
            await dbContext.SaveChangesAsync();

            return(_mapper.Map <SubjectViewModel>(subject));
        }
예제 #4
0
        public SubjectViewModel EditSubject(string id, SubjectInputModel inputModel)
        {
            var subjectFromDb = Repositories.Subjects.GetWithoutTracking()
                                .Find(s => s.Id == id);

            if (subjectFromDb is null)
            {
                throw new TargetException("Subject not found");
            }

            var subject = Mapper.Map <SubjectInputModel, Subject>(inputModel);

            subject.Id = subjectFromDb.Id;

            Repositories.Subjects.Update(subject);

            return(Mapper.Map <Subject, SubjectViewModel>(subject));
        }
예제 #5
0
        public async Task CreateSubject(SubjectInputModel inputModel)
        {
            var teacherId = int.Parse(inputModel.TeacherId);
            var teacher   = _teachersRepository.All().FirstOrDefault(t => t.Id == teacherId);

            if (teacher != null)
            {
                var subject = new Subject
                {
                    Name       = inputModel.Name,
                    YearGrade  = inputModel.YearGrade,
                    SchoolYear = inputModel.SchoolYear,
                    Teacher    = teacher
                };

                await _subjectsRepository.AddAsync(subject);

                await _subjectsRepository.SaveChangesAsync();

                return;
            }

            throw new ArgumentException($"Sorry, we couldn't find teacher with id {teacherId}");
        }
 public IActionResult Save(SubjectInputModel model)
 {
     this.service.Save(model);
     return(this.Ok());
 }
예제 #7
0
 public SubjectViewModel EditSubject([FromRoute] string id, [FromBody] SubjectInputModel inputModel)
 {
     return(SubjectService.EditSubject(id, inputModel));
 }
예제 #8
0
 public void AddSubject([FromBody] SubjectInputModel inputModel)
 {
     SubjectService.AddSubject(inputModel);
 }
예제 #9
0
        public void AddSubject(SubjectInputModel inputModel)
        {
            var subject = Mapper.Map <SubjectInputModel, Subject>(inputModel);

            Repositories.Subjects.Create(subject);
        }