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")); }
public void AddSubject(SubjectBindingModel model) { var subject = new Subject { Name = model.SubjectName }; _subjectRepository.Add(subject); }
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); }
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")); }
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); }
public ActionResult Create(SubjectBindingModel subject) { _subjectService.AddSubject(subject); return(RedirectToAction("Index")); }