public Subject addSubject(CreateSubjectDTO createSubject) { var subject = new Subject() { Name = createSubject.Name }; Create(subject); return(subject); }
public async Task <IActionResult> CreateSubject(CreateSubjectDTO createSubjectDTO) { string token = HttpContext.Request.Headers["Authorization"]; token = token.Replace("Bearer ", string.Empty); var id = _tokenHelper.GetIdByToken(token); var user = await _apiHelper.ReturnUserByMail(createSubjectDTO.UserToAddEmail); if (user == null || user.userRole == 0) { error.Err = "Nie poprawny nauczyciel"; error.Desc = "Wprowadz email nauczyciela jeszcze raz"; return(StatusCode(405, error)); } var classObj = await _apiHelper.ReturnClassByID(createSubjectDTO.ClassID); if (classObj == null) { error.Err = "Nie ma takiej klasy"; error.Desc = "Wprowadź ID klasy jeszcze raz"; return(StatusCode(405, error)); } if (classObj.creatorID != id) { error.Err = "Nie jestes wychowawcą"; error.Desc = "Nie możesz tworzyć przedmiotu"; return(StatusCode(405, error)); } var subject = await _apiHelper.AddSubjectToClass(user.Id, classObj, createSubjectDTO.SubjectName); await _apiHelper.ReplaceClassInfo(subject.ClassObj); return(Ok(subject)); }
public IActionResult CreateSubject([FromBody] CreateSubjectDTO createSubjectDTO) { if (createSubjectDTO == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var subjectObj = _mapper.Map <Subject>(createSubjectDTO); if (!_sRepo.CreateSubject(subjectObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {subjectObj.Title}"); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetSubject", new { subjectId = subjectObj.Id }, subjectObj)); }
public IActionResult addNewSubject([FromBody] CreateSubjectDTO request) => Ok(AccountService.AddNewSubject(request));
public SubjectDTO AddNewSubject(CreateSubjectDTO createSubject) { var subject = SubjectService.addSubject(createSubject); return(new SubjectDTO(subject)); }