Пример #1
0
        public ActionResult <List <InternshipForManagementViewModel> > GetInternshipsForStudentManagement()
        {
            var claim = User.Claims.FirstOrDefault(u => u.Type.Contains("nameidentifier"));

            if (claim != null)
            {
                var userId = claim.Value;
                try
                {
                    var studentId            = _studentService.GetStudentIdForUser(userId);
                    var internships          = _internshipService.GetInternshipsForStudent(studentId);
                    var internshipManagement = new List <InternshipForManagementViewModel>();
                    foreach (var intern in internships)
                    {
                        var companyName      = _internshipService.GetCompanyNameForInternship(intern);
                        var status           = _internshipService.GetStatusForStudentInternship(intern, studentId);
                        var internManagement = InternshipMapper.ToInternshipManagement(intern, status, companyName);
                        internshipManagement.Add(internManagement);
                    }

                    var obj = new InternshipsListObject()
                    {
                        Internships = internshipManagement
                    };
                    return(Ok(JsonConvert.SerializeObject(obj)));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(BadRequest("Studentul nu a fost recunoscut"));
        }