Exemple #1
0
 public async Task <ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > > GetPrintDataByBookAndRegisterRange(StudentRegisterPrintForRangeRequest request)
 {
     return(await studentRegisterService.GetPrintDataForBookAndEntriesRange(request));
 }
Exemple #2
0
        public async Task <ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > > GetPrintDataForBookAndEntriesRange(StudentRegisterPrintForRangeRequest request)
        {
            try
            {
                var studentRegisterEntryFailResponses = new List <ActionResponse <StudentRegisterEntryDto> >();
                var educationProgramsFailResponses    = new List <ActionResponse <StudentEducationProgramsPrintModel> >();
                var printData = new List <StudentRegisterPrintDataAggregatedDto>();

                var range = Enumerable.Range(request.StudentRegisterNumberRangeFrom, request.StudentRegisterNumberRangeTo - request.StudentRegisterNumberRangeFrom);

                await Task.WhenAll(range.Select(async number =>
                {
                    if ((await GetEntryForStudentNumberAndBookNumberAndBookYearDetailed(new StudentRegisterEntryInsertRequest
                    {
                        BookNumber = request.BookNumber,
                        BookYear = request.BookYear,
                        StudentRegisterNumber = number
                    })).IsNotSuccess(out ActionResponse <StudentRegisterEntryDto> registerEntryResponse, out StudentRegisterEntryDto studentRegisterEntry))
                    {
                        studentRegisterEntryFailResponses.Add(registerEntryResponse);
                    }
                    else if (studentRegisterEntry != null)
                    {
                        if ((await studentService.GetStudentsEducationPrograms(studentRegisterEntry.Student.Id))
                            .IsNotSuccess(out ActionResponse <StudentEducationProgramsPrintModel> studentEducationProgramsResponse, out StudentEducationProgramsPrintModel studentEducationPrograms))
                        {
                            educationProgramsFailResponses.Add(studentEducationProgramsResponse);
                        }
                        else
                        {
                            printData.Add(new StudentRegisterPrintDataAggregatedDto
                            {
                                StudentRegisterEntry     = studentRegisterEntry,
                                StudentEducationPrograms = studentEducationPrograms
                            });
                        }
                    }
                }));

                var anyRegisterFails    = studentRegisterEntryFailResponses.Any();
                var anyEduProgramsFails = educationProgramsFailResponses.Any();

                if (!anyRegisterFails && !anyEduProgramsFails)
                {
                    return(await ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > .ReturnSuccess(printData));
                }
                else
                {
                    if ((anyRegisterFails && studentRegisterEntryFailResponses.All(r => r.ActionResponseType != ActionResponseTypeEnum.Success)) ||
                        (anyEduProgramsFails && educationProgramsFailResponses.All(r => r.ActionResponseType != ActionResponseTypeEnum.Success)))
                    {
                        return(await ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > .ReturnError("Greška prilikom dohvata podataka.", printData));
                    }

                    return(await ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > .ReturnWarning("Postoje greške prilikom dohvata zapisa matične knjige.", printData));
                }
            }
            catch (Exception)
            {
                return(await ActionResponse <List <StudentRegisterPrintDataAggregatedDto> > .ReturnError("Greška prilikom dohvata zapisa."));
            }
        }