Ejemplo n.º 1
0
        public Table getTableWithStudentsInformation(ProposalDocRecord record)
        {
            Table studentsTable = new Table();

            studentsTable.AppendChild <TableProperties>(_tablePropertiesGetter.getHorizontalBorderTableProperties());

            TableRow stdTableRow1 = new TableRow();

            stdTableRow1.Append(new TableRowProperties(new TableRowHeight()
            {
                HeightType = HeightRuleValues.Exact, Val = 180
            }));
            TableCell stdTableCell11 = new TableCell();

            stdTableCell11.Append(_tablePropertiesGetter.getTableCellPropFilled("1559", "000000"));
            stdTableCell11.Append(_paragraphGetter.getSmallCenteredText(""));
            TableCell stdTableCell12 = new TableCell();

            stdTableCell12.Append(_tablePropertiesGetter.getTableCellPropFilled("3694", "CCCCCC"));
            stdTableCell12.Append(_paragraphGetter.getSmallCenteredText(_localizer["Imię i nazwisko"]));
            TableCell stdTableCell13 = new TableCell();

            stdTableCell13.Append(_tablePropertiesGetter.getTableCellPropFilled("1575", "CCCCCC"));
            stdTableCell13.Append(_paragraphGetter.getSmallCenteredText(_localizer["Nr albumu"]));
            TableCell stdTableCell14 = new TableCell();

            stdTableCell14.Append(_tablePropertiesGetter.getTableCellPropFilled("2351", "CCCCCC"));
            stdTableCell14.Append(_paragraphGetter.getSmallCenteredText(_localizer["Data i podpis"]));
            stdTableRow1.Append(stdTableCell11, stdTableCell12, stdTableCell13, stdTableCell14);

            studentsTable.Append(stdTableRow1);


            EKontoStudent[] students = _studentGetter.GetMany(record.StudentIndexes).Body();
            for (int i = 0; i < 4; i++)
            {
                bool nextStudent = i < students.Length;

                TableRow stdTableRow2 = new TableRow();
                stdTableRow2.Append(new TableRowProperties(new TableRowHeight()
                {
                    Val = 300
                }));
                TableCell stdTableCell21 = new TableCell();
                stdTableCell21.Append(_tablePropertiesGetter.getTableCellPropCentered("1559"));
                stdTableCell21.Append(_paragraphGetter.getNormalRightText(_localizer["Student:"]));
                TableCell stdTableCell22 = new TableCell();
                stdTableCell22.Append(_tablePropertiesGetter.getTableCellPropCentered("3694"));
                stdTableCell22.Append(_paragraphGetter.getNormalText(nextStudent ? students[i].names[0] + " " + students[i].surname : ""));
                TableCell stdTableCell23 = new TableCell();
                stdTableCell23.Append(_tablePropertiesGetter.getTableCellPropCentered("1575"));
                stdTableCell23.Append(_paragraphGetter.getNormalText(nextStudent ? students[i].studentNumber : ""));
                TableCell stdTableCell24 = new TableCell();
                stdTableCell24.Append(_tablePropertiesGetter.getTableCellPropCentered("2351"));
                stdTableCell24.Append(_paragraphGetter.getNormalText(""));
                stdTableRow2.Append(stdTableCell21, stdTableCell22, stdTableCell23, stdTableCell24);

                studentsTable.Append(stdTableRow2);
            }

            return(studentsTable);
        }
Ejemplo n.º 2
0
        public async Task <IServiceResult <ProposalViewModel> > Update(
            int id,
            ProposalRegistration inputData)
        {
            var proposal = _context.Proposals.Include(p => p.Students).FirstOrDefault(p => p.Id == id);

            if (proposal == null)
            {
                return(ServiceResult <ProposalViewModel> .Error(
                           $"Proposal with id {id} does not exist"
                           ));
            }

            var courseResult = await _courseGetter.Get(inputData.CourseId);

            if (!courseResult.Successful())
            {
                return(ServiceResult <ProposalViewModel> .Error(courseResult.GetAggregatedErrors()));
            }

            var studentGroupValidatorResult = await _studentGroupValidator.IsStudentGroupValidFor(inputData);

            if (!studentGroupValidatorResult.Successful())
            {
                return(ServiceResult <ProposalViewModel> .Error(studentGroupValidatorResult.GetAggregatedErrors()));
            }

            var isStudentGroupValid = studentGroupValidatorResult.Body();

            if (!isStudentGroupValid)
            {
                return(ServiceResult <ProposalViewModel> .Error("The given students are not valid"));
            }

            var userResult = await _userGetter.GetCurrentUser();

            if (!userResult.Successful())
            {
                var errors = userResult.GetAggregatedErrors();
                return(ServiceResult <ProposalViewModel> .Error(errors));
            }

            var currentUser = userResult.Body();
            var promoter    =
                await _context
                .Promoters
                .FirstOrDefaultAsync(p => p.UserId == currentUser.Id);

            if (promoter == null)
            {
                return(ServiceResult <ProposalViewModel> .Error("The current user has no associated promoter"));
            }

            if (proposal.PromoterId != promoter.Id)
            {
                return(ServiceResult <ProposalViewModel> .Error(
                           $"Promoter with id {promoter.Id} has no proposal with id {id}"
                           ));
            }

            var studentsResult = await _studentGetter.GetMany(inputData.Students);

            if (!studentsResult.Successful())
            {
                return(ServiceResult <ProposalViewModel> .Error(studentsResult.GetAggregatedErrors()));
            }
            var newStudents = studentsResult.Body();

            var proposalStatusResult = _proposalStatusGetter.CalculateProposalStatus(newStudents, inputData.MaxNumberOfStudents);

            if (!proposalStatusResult.Successful())
            {
                return(ServiceResult <ProposalViewModel> .Error(proposalStatusResult.GetAggregatedErrors()));
            }
            var proposalStatus = proposalStatusResult.Body();

            foreach (var student in proposal.Students)
            {
                student.ProposalId = null;
            }
            await _context.SaveChangesAsync();

            proposal          = _mapper.Map(inputData, proposal);
            proposal.Students = newStudents;
            proposal.Status   = proposalStatus;
            _context.Proposals.Update(proposal);
            await _context.SaveChangesAsync();

            var proposalViewModels = _mapper.Map <ProposalViewModel>(proposal);

            return(ServiceResult <ProposalViewModel> .Success(proposalViewModels));
        }