Пример #1
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
 public IActionResult addNewSubject([FromBody] CreateSubjectDTO request)
 => Ok(AccountService.AddNewSubject(request));
Пример #5
0
        public SubjectDTO AddNewSubject(CreateSubjectDTO createSubject)
        {
            var subject = SubjectService.addSubject(createSubject);

            return(new SubjectDTO(subject));
        }