Ejemplo n.º 1
0
        public ActionResult <List <InternshipMainAttributesViewModel> > GetInternshipsForStudent()
        {
            var claim = User.Claims.FirstOrDefault(u => u.Type.Contains("nameidentifier"));

            if (claim != null)
            {
                var userId = claim.Value;
                try
                {
                    var studentId     = _studentService.GetStudentIdForUser(userId);
                    var internshipsDb = _internshipService.GetInternshipsForStudent(studentId);
                    var viewModels    = new List <InternshipMainAttributesViewModel>();
                    foreach (var internship in internshipsDb)
                    {
                        var viewModel = InternshipMapper.ToViewModel(internship);
                        viewModels.Add(viewModel);
                    }
                    return(Ok(viewModels));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(BadRequest("Studentul nu a fost recunoscut"));
        }
Ejemplo n.º 2
0
        public ActionResult <InternshipMainAttributesViewModel> AddInternship(InternshipAddViewModel internship)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var userID = User.GetUserId();
                if (userID == string.Empty)
                {
                    return(BadRequest("Compania nu a fost recunoscuta"));
                }
                var companyID       = _companyService.GetCompanyIdForUser(userID);
                var addedInternship = _internshipService.AddInternship(InternshipAddMapper.ToInternship(internship, companyID));


                return(Ok(InternshipMapper.ToViewModel(addedInternship)));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }