public async Task <ActionResult> DownloadContract(int userId, int internshipId)
        {
            User user = _context.Users.Include(x => x.Address).Include(x => x.Classroom).Where(x => x.Id == userId).FirstOrDefaultAsync().Result;

            if (user == null)
            {
                return(BadRequest("Uživatel nenalezen!"));
            }
            Internship internship = _internshipManager.Read(internshipId).Result;

            if (internship == null)
            {
                return(BadRequest("Praxe nenalezena!"));
            }
            string formatedAddressInternship = internship.CompanyAddress.StreetName + " " + internship.CompanyAddress.HouseNumber + ", " + internship.CompanyAddress.PostalCode + " " + internship.CompanyAddress.City;
            var    dbRecords = _context.Records.Where(x => x.InternshipId == internshipId);

            List <RecordModel> records = new List <RecordModel>();

            foreach (var i in dbRecords)
            {
                records.Add(new RecordModel {
                    Date = i.DateOfRecord.ToString("dd.MM.yyy"), Description = i.WorkDescription, NumberOfHours = i.NumberOfHours
                });
            }

            string documentBody = await _razorViewToStringRenderer.RenderViewToStringAsync("/Prints/Records.cshtml", new RecordPrintModel
            {
                RecordList                     = records,
                StudentName                    = user.FirstName + " " + user.LastName,
                Classroom                      = user.Classroom.Name,
                CompanyAddress                 = formatedAddressInternship,
                CompanyRepresentative          = internship.CompanyRepresentative,
                CompanyRepresentativeEmail     = internship.CompaniesRepresentativeEmail,
                CompanyRepresentativeTelephone = internship.CompaniesRepresentativeTelephoneNumber,
                Company = internship.Company.Name
            });

            MemoryStream memory = new MemoryStream(Encoding.UTF8.GetBytes(documentBody));

            return(File(memory, "text/html", "random.html"));
        }
Exemple #2
0
 public async Task <Internship> Get(int id)
 {
     return(await _internshipManager.Read(id));
 }