public IActionResult GetStudentProfile()
        {
            try
            {
                var studentProfileDto = new StudentProfileDto()
                {
                    Name           = "",
                    Description    = "",
                    FacultyId      = "",
                    FacultyName    = "",
                    Specialization = "",
                    StudyYear      = 1,
                    Email          = "",
                    Telephone      = "",
                    City           = ""
                };
                var studentProfile = _studentProfileRepository.Get(User.FindFirst(JwtRegisteredClaimNames.Sid).Value);
                if (studentProfile != null)
                {
                    studentProfileDto = Mapper.Map <StudentProfileDto>(studentProfile);
                }

                return(Ok(studentProfileDto));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"An exception was thrown: ", ex);
                return(StatusCode(500, "A problem happend while handeling your request."));
            }
        }
Пример #2
0
        public IActionResult CreateAplication([FromBody] AplicationCreateDto aplicationCreateDto)
        {
            try
            {
                // Validation
                if (aplicationCreateDto == null)
                {
                    return(BadRequest());
                }
                var activity = _activityRepository.Get(aplicationCreateDto.ActivityId);
                if (activity == null)
                {
                    return(BadRequest($"Activity with id {aplicationCreateDto.ActivityId} was not found"));
                }


                // Get student data
                var studentid      = User.FindFirst(JwtRegisteredClaimNames.Sid).Value;
                var studentProfile = _studentProfileRepository.Get(studentid);
                if (studentProfile == null)
                {
                    return(BadRequest($"Student profile was not found"));
                }

                // Stundet can apply only once
                if (_aplicationRepository.GetAllByActivityAndStudent(studentid, aplicationCreateDto.ActivityId).Count() > 0)
                {
                    return(BadRequest($"You have already applyed for this activity"));
                }

                // Create the new object
                var aplication = Mapper.Map <Aplication>(aplicationCreateDto);
                aplication.UserId            = studentid;
                aplication.FacultyId         = studentProfile.FacultyId;
                aplication.Specialization    = studentProfile.Specialization;
                aplication.StudyYear         = studentProfile.StudyYear;
                aplication.Status            = 0;
                aplication.CreatedDate       = DateTime.Now;
                aplication.ModifiedStateDate = DateTime.Now;

                _aplicationRepository.Add(aplication);

                if (!_aplicationRepository.Save())
                {
                    return(StatusCode(500, "A problem happend while handeling your request."));
                }

                var aplicationDtoToReturn = Mapper.Map <AplicationDto>(aplication);

                return(CreatedAtRoute("GetAplication", new { id = aplicationDtoToReturn.Id }, aplicationDtoToReturn));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"An exception was thrown: ", ex);
                return(StatusCode(500, "A problem happend while handeling your request."));
            }
        }