private async Task <ActionResponse <EducationProgramDto> > CheckForDelete(int id)
        {
            try
            {
                var subjectCheckQuery = unitOfWork.GetGenericRepository <Subject>()
                                        .ReadAllActiveAsQueryable()
                                        .Where(e => e.EducationProgramId == id);

                if (subjectCheckQuery.Any())
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                var planCheckQuery = unitOfWork.GetGenericRepository <Plan>()
                                     .ReadAllActiveAsQueryable()
                                     .Where(e => e.EducationProgramId == id);

                if (planCheckQuery.Any())
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                var sgCheckQuery = unitOfWork.GetGenericRepository <StudentGroup>()
                                   .ReadAllActiveAsQueryable()
                                   .Where(e => e.ProgramId == id);

                if (sgCheckQuery.Any())
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                var sreCheckQuery = unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                                    .ReadAllActiveAsQueryable()
                                    .Where(e => e.EducationProgramId == id);

                if (sreCheckQuery.Any())
                {
                    return(await ActionResponse <EducationProgramDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                return(await ActionResponse <EducationProgramDto> .ReturnSuccess(null, "Brisanje moguće."));
            }
            catch (Exception)
            {
                return(await ActionResponse <EducationProgramDto> .ReturnError("Greška prilikom provjere za brisanja programa."));
            }
        }
示例#2
0
        private async Task <ActionResponse <StudentDto> > CheckForDelete(int id)
        {
            try
            {
                var checkQuery = unitOfWork.GetGenericRepository <StudentClassAttendance>()
                                 .ReadAllActiveAsQueryable()
                                 .Where(e => e.StudentId == id);

                if (checkQuery.Any())
                {
                    return(await ActionResponse <StudentDto> .ReturnWarning(null, "error.delete_linked_data"));
                }

                return(await ActionResponse <StudentDto> .ReturnSuccess(null, "Brisanje moguće."));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentDto> .ReturnError("Greška prilikom provjere za brisanja studenta."));
            }
        }
示例#3
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."));
            }
        }
示例#4
0
        public async Task <ActionResponse <StudentRegisterEntryInsertRequest> > PrepareForInsert(StudentRegisterEntryInsertRequest request)
        {
            try
            {
                var alreadyInserted = unitOfWork.GetGenericRepository <StudentRegisterEntry>()
                                      .ReadAllActiveAsQueryable()
                                      .Where(e => e.EducationProgramId == request.EducationProgramId)
                                      .Any(e => e.StudentsInGroups.StudentId == request.StudentId);

                if (alreadyInserted)
                {
                    return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnWarning("Ovaj student već je unuesen u matičnu knjigu za izabrani program. Molimo provjerite podatke."));
                }


                ActionResponse <List <StudentRegisterDto> > registerResponse;

                if (!request.BookNumber.HasValue)
                {
                    if ((await GetAllNotFull()).IsNotSuccess(out registerResponse, out List <StudentRegisterDto> notFullRegisters))
                    {
                        return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnError(registerResponse.Message));
                    }

                    if (notFullRegisters.Any(sr => sr.BookYear == request.BookYear))
                    {
                        var selectedBook = notFullRegisters.OrderByDescending(b => b.BookNumber).FirstOrDefault();
                        request.BookNumber = selectedBook.BookNumber;
                        request.BookYear   = selectedBook.BookYear;
                        request.BookId     = selectedBook.Id;
                    }
                    else
                    {
                        if ((await GetAll()).IsNotSuccess(out registerResponse, out List <StudentRegisterDto> registers))
                        {
                            return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnError("Greška prilikom dohvata postojećih matičnih knjiga."));
                        }

                        var        minBookNumber = registers.Min(r => r.BookNumber) ?? 0;
                        var        maxBookNumber = registers.Max(r => r.BookNumber) ?? 0;
                        List <int> fullList      = Enumerable.Range(minBookNumber, maxBookNumber - minBookNumber + 1).ToList();
                        List <int> realList      = registers.Select(r => r.BookNumber.Value).ToList();

                        var missingNums         = fullList.Except(realList).ToList();
                        var nextAvailableNumber = missingNums.Min() + 1;

                        request.BookNumber    = nextAvailableNumber;
                        request.CreateNewBook = true;
                    }
                }
                else
                {
                    var chosenBook = unitOfWork.GetGenericRepository <StudentRegister>()
                                     .ReadAllActiveAsQueryable()
                                     .Where(b => b.BookNumber == request.BookNumber && b.BookYear == request.BookYear)
                                     .FirstOrDefault();

                    if (chosenBook == null)
                    {
                        request.CreateNewBook = true;
                    }
                    request.BookId = chosenBook?.Id;
                }

                if (!request.StudentRegisterNumber.HasValue)
                {
                    var fullList = Enumerable.Range((request.BookNumber.Value * 200) - 199, 200).ToList();
                    if (request.CreateNewBook)
                    {
                        request.StudentRegisterNumber = fullList.Min();
                    }
                    else
                    {
                        if ((await GetById(request.BookId.Value))
                            .IsNotSuccess(out ActionResponse <StudentRegisterDto> bookResponse, out StudentRegisterDto registerDto))
                        {
                            return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnError(bookResponse.Message));
                        }
                        request.StudentRegisterNumber = registerDto.FreeStudentRegisterNumbers.Min();
                    }
                }
                return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnSuccess(request));
            }
            catch (Exception)
            {
                return(await ActionResponse <StudentRegisterEntryInsertRequest> .ReturnError("Greška prilikom pripreme za unos matične knjige."));
            }
        }