Пример #1
0
        public ActionResult <List <InternshipMainAttributesViewModel> > GetAllInternships()
        {
            var userId = User.GetUserId();

            if (userId != string.Empty)
            {
                try
                {
                    var companyId         = _companyService.GetCompanyIdForUser(userId);
                    var internshipsDB     = _internshipService.GetInternshipsForCompany(companyId);
                    var closedInternships = internshipsDB.Where(i => i.End <= DateTime.Now)
                                            .OrderByDescending(i => i.End);
                    var activeInternships = internshipsDB.Where(i => i.End > DateTime.Now)
                                            .OrderBy(i => i.End);
                    var sortedInternships = activeInternships.Union(closedInternships);
                    var viewModels        = new List <InternshipMainAttributesViewModel>();
                    foreach (var internship in sortedInternships)
                    {
                        var viewModel = Mappers.InternshipMapper.ToViewModel(internship);
                        viewModels.Add(viewModel);
                    }
                    return(Ok(viewModels));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
            return(BadRequest("Compania nu a fost recunoscuta"));
        }
        public ActionResult <IList <ApplicationsPerYearViewModel> > GetApplicationsPerYear()
        {
            var userID = User.GetUserId();

            if (userID == string.Empty)
            {
                return(BadRequest("Compania nu a fost recunoscuta"));
            }

            var applicationsPerYear        = new List <ApplicationsPerYearViewModel>();
            IList <Internship> internships = null;

            try
            {
                var id = _companyService.GetCompanyIdForUser(userID);
                internships = _internshipService.GetInternshipsForCompany(id);
                var years = internships.Select(i => i.Start.Year).Distinct().ToList();
                foreach (var year in years)
                {
                    int nrApplications = _statisticsService.GetNrApplicationsPerYear(id, year);
                    ApplicationsPerYearViewModel viewModel = new ApplicationsPerYearViewModel()
                    {
                        Year             = year,
                        NumberOfStudents = nrApplications
                    };
                    applicationsPerYear.Add(viewModel);
                }
                ;

                return(Ok(applicationsPerYear));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }