예제 #1
0
        public async Task <IActionResult> AddSubject(SubjectBindingModel subjectBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var subjectCategoryModel =
                await _subjectCategoryService.GetSubjectCategoryById(subjectBindingModel.SubjectCategoryId);

            if (subjectCategoryModel == null)
            {
                return(BadRequest("Could not find the subject category."));
            }

            var subjectModel = new SubjectModel
            {
                Title = subjectBindingModel.Title,
                SubjectCategoryModel = subjectCategoryModel
            };

            var successful = await _subjectService.AddSubjectAsync(subjectModel);

            if (!successful)
            {
                return(BadRequest("Could not add the subject"));
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public void AddSubject(SubjectBindingModel model)
        {
            var subject = new Subject
            {
                Name = model.SubjectName
            };

            _subjectRepository.Add(subject);
        }
예제 #3
0
        public async Task CreateAsync(SubjectBindingModel model)
        {
            Subject subject = new Subject();

            subject.Name = model.Name;

            await this.dbContext.Subjects.AddAsync(subject);

            await this.dbContext.SaveChangesAsync();
        }
        public Subject EditSubject(SubjectBindingModel model)
        {
            var subject = _unitOfWork.SubjectsRepository.Data.FirstOrDefault(d => d.Id == model.Id);

            if (subject == null)
            {
                return(null);
            }

            subject.Name = model.Name;

            var result = _unitOfWork.SubjectsRepository.Update(subject);

            return(result);
        }
예제 #5
0
        public async Task <IActionResult> Create(SubjectBindingModel model)
        {
            Subject subjectFromDb = this.subjectsService.GetByName(model.Name);

            bool isSubjectAlreadyInDb = subjectFromDb != null;

            if (isSubjectAlreadyInDb)
            {
                return(this.RedirectToAction("index"));
            }

            await this.subjectsService.CreateAsync(model);

            return(this.RedirectToAction("index"));
        }
예제 #6
0
        public async Task <IActionResult> AddSubject()
        {
            var subjectCategories = await _subjectCategoryService.GetAllSubjectCategoryAsync();

            var categoryDescriptions = subjectCategories
                                       .Select(x => new SelectListItem
            {
                Text  = x.Description,
                Value = x.Id.ToString()
            }).ToList();

            var subjectBindingModel = new SubjectBindingModel
            {
                SubjectCategoryDescription = categoryDescriptions
            };

            return(View(subjectBindingModel));
        }
        public async Task <Subject> AddSubject(SubjectBindingModel model)
        {
            var exist = _unitOfWork.SubjectsRepository.Data.Any(d => d.Name.ToLower() == model.Name.ToLower());

            if (exist)
            {
                return(null);
            }

            var subject = new Subject()
            {
                Name = model.Name
            };

            var result = await _unitOfWork.SubjectsRepository.AddAsync(subject);

            return(result);
        }
예제 #8
0
 public ActionResult Create(SubjectBindingModel subject)
 {
     _subjectService.AddSubject(subject);
     return(RedirectToAction("Index"));
 }