Exemplo n.º 1
0
        public IActionResult WorkersAdd(SpecificWorkerModel workerModel, List <long> competences)
        {
            ViewBag.Competences = _context.Set <CompetencesModel>().ToList();
            foreach (var competenceId in competences)
            {
                var competence        = _context.Set <CompetencesModel>().Find(competenceId);
                var workerCompetences = new SpecificWorkerCompetencesModel
                {
                    Competence = competence,
                    Worker     = workerModel
                };
                workerModel.SpecificWorkerCompetencesModels.Add(workerCompetences);
            }

            var employee = _workerService.TryGetEmployeeWithUsername(User.Identity.Name);

            if (employee == default)
            {
                workerModel.Email = User.Identity.Name;
            }

            _context.Set <SpecificWorkerModel>().Add(workerModel);

            var user = _context.Set <AppIdentityUser>().FirstOrDefault(u => u.Email == workerModel.Email);

            if (user != default)
            {
                user.Employee = workerModel;
            }

            _context.SaveChanges();

            return(RedirectToAction("Workers"));
        }
Exemplo n.º 2
0
        public static MemoryStream GetPdfOfAttestation(long id, DbContext context)
        {
            var memoryStream = new MemoryStream();
            var document     = new Document(PageSize.A4, MarginLeft, MarginRight, MarginTop, MarginBottom);

            document.AddTitle("Результаты аттестации");
            document.AddCreationDate();
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);

            EncodingProvider encProvider = CodePagesEncodingProvider.Instance;

            Encoding.RegisterProvider(encProvider);
            string arial = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "arial.ttf");

            BaseFont baseFont = BaseFont.CreateFont(arial, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            Font body     = new Font(baseFont, 10, Font.NORMAL, BaseColor.BLACK);
            Font boldBody = new Font(baseFont, 10, Font.BOLD, BaseColor.BLACK);
            Font head     = new Font(baseFont, 16, Font.NORMAL, BaseColor.BLACK);

            var attestation = context.Set <AttestationModel>().First(x => x.Id == id);

            context.Entry(attestation).Collection(x => x.AttestationAnswer).Load();

            foreach (var attestationAnswer in attestation.AttestationAnswer)
            {
                attestationAnswer.Answer = context.Set <AnswerModel>().Find(attestationAnswer.AnswerId);
            }

            attestation.AttestationAnswer = attestation.AttestationAnswer.Where(x => x.Answer.IsSkipped == false).OrderBy(x => x.Answer.NumberOfAsk).ToList();

            var testedCompetences = attestation.IdsTestedCompetences;

            List <CompetencesModel> competencesModels = new List <CompetencesModel>();

            if (testedCompetences == null)
            {
                testedCompetences = new List <long>();
            }

            foreach (var testedCompetence in testedCompetences)
            {
                competencesModels.Add(context.Set <CompetencesModel>().Find(testedCompetence));
            }

            var worker = context.Set <SpecificWorkerModel>().Find((int)attestation.WorkerId);

            document.Open();
            if (worker == null)
            {
                worker = new SpecificWorkerModel();
                document.Add(new Paragraph($"Аттестация удалённого работника", head));
                document.Add(new Paragraph(attestation.Date.ToString("d"), head));
                document.Add(new Paragraph(" ", body));
            }

            else
            {
                document.Add(new Paragraph($"{worker.FullName} - результаты аттестации", head));
                document.Add(new Paragraph(attestation.Date.ToString("d"), head));
                document.Add(new Paragraph(" ", body));
            }
            document.Add(new Paragraph("Техническое интервью", head));
            document.Add(new Paragraph(" ", body));
            document.Add(new Paragraph("Блоки компетенций:", boldBody));
            foreach (var competencesModel in competencesModels)
            {
                if (competencesModel == null)
                {
                    document.Add(new Paragraph($"  -   компетенция была удалена", body));
                }
                else
                {
                    document.Add(new Paragraph($"  -   {competencesModel.Competence}", body));
                }
            }

            document.Add(new Paragraph(" ", body));

            document.Add(new Paragraph("Выявлены пробелы в знаниях:", boldBody));
            document.Add(new Paragraph($"{attestation.Problems}", body));

            document.Add(new Paragraph(" ", body));

            document.Add(new Paragraph("Дальнейшие действия", head));
            document.Add(new Paragraph($"{attestation.NextMoves}", body));

            document.Add(new Paragraph(" ", body));

            document.Add(new Paragraph("Обратная связь от руководителя проекта:", boldBody));
            document.Add(new Paragraph($"{attestation.Feedback}", body));

            document.Add(new Paragraph(" ", body));

            PdfPTable table = new PdfPTable(4);

            table.TotalWidth  = document.PageSize.Width - 72f - 65f;
            table.LockedWidth = true;
            float[] widths1 = new float[] { 0.55f, 4f, 0.7f, 4f };
            table.SetWidths(widths1);
            table.HorizontalAlignment = 0;

            PdfPCell tablecell11 = new PdfPCell(new Phrase($"№", body));

            table.AddCell(tablecell11);

            PdfPCell tablecell12 = new PdfPCell(new Phrase($"Вопрос", body));

            table.AddCell(tablecell12);

            PdfPCell tablecell13 = new PdfPCell(new Phrase("Верно", body));

            table.AddCell(tablecell13);

            PdfPCell tablecell14 = new PdfPCell(new Phrase("Комментарий", body));

            table.AddCell(tablecell14);

            foreach (var answer in attestation.AttestationAnswer)
            {
                PdfPCell tablecellx1 = new PdfPCell(new Phrase($"{answer.Answer.NumberOfAsk}", body));
                tablecellx1.PaddingLeft = LeftPadding;
                table.AddCell(tablecellx1);

                PdfPCell tablecellx2 = new PdfPCell(new Phrase($"{answer.Answer.Question}", body));
                tablecellx2.PaddingLeft = LeftPadding;
                table.AddCell(tablecellx2);

                PdfPCell tablecellx3 = new PdfPCell();
                if (answer.Answer.IsRight)
                {
                    tablecellx3 = new PdfPCell(new Phrase("+", body));
                }
                else
                {
                    tablecellx3 = new PdfPCell(new Phrase("-", body));
                }
                tablecellx3.PaddingLeft = LeftPadding;
                table.AddCell(tablecellx3);

                PdfPCell tablecellx4 = new PdfPCell(new Phrase($"{answer.Answer.Commentary}", body));
                tablecellx4.PaddingLeft = LeftPadding;
                table.AddCell(tablecellx4);
            }
            document.Add(table);
            document.Close();

            byte[]       file = memoryStream.ToArray();
            MemoryStream ms   = new MemoryStream();

            ms.Write(file, 0, file.Length);
            ms.Position = 0;

            return(ms);
        }