Exemplo n.º 1
0
        public async Task <IActionResult> EditRegionReport(int reportId,
                                                           [FromBody] RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _RegionAnnualReportService.EditAsync(reportId, regionAnnualReportQuestions);

                    _logger.LogInformation($"User (id: {(await _userManager.GetUserAsync(User)).Id}) edited annual report (id: {reportId})");
                    return(StatusCode(StatusCodes.Status200OK, new { message = "Річний звіт округи змінено" }));
                }
                catch (InvalidOperationException)
                {
                    _logger.LogError($"Annual report (id: {reportId}) can not be edited");
                    return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Виникла помилка при внесенні змін до річного звіту округи" }));
                }
                catch (NullReferenceException)
                {
                    _logger.LogError($"Annual report (id: {reportId}) not found");
                    return(StatusCode(StatusCodes.Status404NotFound, new { message = "Річний звіт округи не знайдено" }));
                }
            }
            return(BadRequest(ModelState));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateRegionAnnualReportById(int id, int year,
                                                                       [FromBody] RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            try
            {
                var annualreport = await _RegionAnnualReportService.CreateByNameAsync(await _userManager.GetUserAsync(User), id, year, regionAnnualReportQuestions);

                return(StatusCode(StatusCodes.Status200OK, annualreport));
            }
            catch (NullReferenceException)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            catch (UnauthorizedAccessException)
            {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }
        }
        ///<inheritdoc/>
        public async Task EditAsync(int reportId, RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            var regionAnnualReport = await _repositoryWrapper.RegionAnnualReports.GetFirstOrDefaultAsync(
                predicate : a => a.ID == reportId && a.Status == AnnualReportStatus.Unconfirmed);

            if (regionAnnualReport.Status != AnnualReportStatus.Unconfirmed)
            {
                throw new InvalidOperationException();
            }

            regionAnnualReport.StateOfPreparation = regionAnnualReportQuestions.StateOfPreparation;

            regionAnnualReport.Characteristic = regionAnnualReportQuestions.Characteristic;

            regionAnnualReport.ChurchCooperation = regionAnnualReportQuestions.ChurchCooperation;

            regionAnnualReport.InvolvementOfVolunteers = regionAnnualReportQuestions.InvolvementOfVolunteers;

            regionAnnualReport.ImportantNeeds = regionAnnualReportQuestions.ImportantNeeds;

            regionAnnualReport.SocialProjects = regionAnnualReportQuestions.SocialProjects;

            regionAnnualReport.StatusOfStrategy = regionAnnualReportQuestions.StatusOfStrategy;

            regionAnnualReport.SuccessStories = regionAnnualReportQuestions.SuccessStories;

            regionAnnualReport.ProblemSituations = regionAnnualReportQuestions.ProblemSituations;

            regionAnnualReport.TrainedNeeds = regionAnnualReportQuestions.TrainedNeeds;

            regionAnnualReport.PublicFunding = regionAnnualReportQuestions.PublicFunding;

            regionAnnualReport.Fundraising = regionAnnualReportQuestions.Fundraising;

            regionAnnualReport = await SetMembersInfoAsync(regionAnnualReport);

            _repositoryWrapper.RegionAnnualReports.Update(regionAnnualReport);
            await _repositoryWrapper.SaveAsync();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateRegionAnnualReportById(int id, int year,
                                                                       [FromBody] RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            try
            {
                var annualreport =
                    await _RegionAnnualReportService.CreateByNameAsync(await _userManager.GetUserAsync(User), id, year,
                                                                       regionAnnualReportQuestions);

                return(StatusCode(StatusCodes.Status201Created, new { message = "Річний звіт округи успішно створено!", report = annualreport }));
            }
            catch (NullReferenceException)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            catch (UnauthorizedAccessException)
            {
                return(StatusCode(StatusCodes.Status403Forbidden));
            }
            catch (InvalidOperationException)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
        }
Exemplo n.º 5
0
        ///<inheritdoc/>
        public async Task <RegionAnnualReportDTO> CreateByNameAsync(User claimsPrincipal, int id, int year,
                                                                    RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            var region = await _repositoryWrapper.Region.GetFirstOrDefaultAsync(a => a.ID == id);

            if (!await _regionAccessService.HasAccessAsync(claimsPrincipal, region.ID))
            {
                throw new UnauthorizedAccessException("User doesn't have access");
            }

            if (await CheckCreatedAsync(id, year))
            {
                throw new InvalidOperationException("Report is already crated!");
            }

            var annualReports = (await _repositoryWrapper.AnnualReports.GetAllAsync(a => a.Date.Year == year && a.City.RegionId == id && a.Status == AnnualReportStatus.Confirmed))
                                .Where(result => result != null).ToList();

            var membersStatistics = (await _repositoryWrapper.MembersStatistics.GetAllAsync(predicate: m => m.AnnualReport.City.RegionId == id))
                                    .Where(result => result != null).ToList();

            var regionAnnualReport = new RegionAnnualReport()
            {
                RegionName = region.RegionName,

                RegionId = id,

                Date = DateTime.Now,

                NumberOfSeigneurMembers = membersStatistics.Select(x => x.NumberOfSeigneurMembers).Sum(),

                NumberOfSeigneurSupporters = membersStatistics.Select(x => x.NumberOfSeigneurSupporters).Sum(),

                NumberOfSeniorPlastynMembers = membersStatistics.Select(x => x.NumberOfSeniorPlastynMembers).Sum(),

                NumberOfSeniorPlastynSupporters = membersStatistics.Select(x => x.NumberOfSeniorPlastynSupporters).Sum(),

                NumberOfUnatstvaSkobVirlyts = membersStatistics.Select(x => x.NumberOfUnatstvaSkobVirlyts).Sum(),

                NumberOfUnatstvaProspectors = membersStatistics.Select(x => x.NumberOfUnatstvaProspectors).Sum(),

                NumberOfUnatstvaMembers = membersStatistics.Select(x => x.NumberOfUnatstvaMembers).Sum(),

                NumberOfUnatstvaSupporters = membersStatistics.Select(x => x.NumberOfUnatstvaSupporters).Sum(),

                NumberOfUnatstvaNoname = membersStatistics.Select(x => x.NumberOfUnatstvaNoname).Sum(),

                NumberOfNovatstva = membersStatistics.Select(x => x.NumberOfNovatstva).Sum(),

                NumberOfPtashata = membersStatistics.Select(x => x.NumberOfPtashata).Sum(),

                NumberOfSeatsPtashat = annualReports.Select(x => x.NumberOfSeatsPtashat).Sum(),

                NumberOfIndependentRiy = annualReports.Select(x => x.NumberOfIndependentRiy).Sum(),

                NumberOfClubs = annualReports.Select(x => x.NumberOfClubs).Sum(),

                NumberOfIndependentGroups = annualReports.Select(x => x.NumberOfIndependentGroups).Sum(),

                NumberOfPlastpryiatMembers = annualReports.Select(x => x.NumberOfPlastpryiatMembers).Sum(),

                NumberOfBeneficiaries = annualReports.Select(x => x.NumberOfBeneficiaries).Sum(),

                NumberOfHonoraryMembers = annualReports.Select(x => x.NumberOfHonoraryMembers).Sum(),

                NumberOfAdministrators = annualReports.Select(x => x.NumberOfAdministrators).Sum(),

                NumberOfTeacherAdministrators = annualReports.Select(x => x.NumberOfTeacherAdministrators).Sum(),

                NumberOfTeachers = annualReports.Select(x => x.NumberOfTeachers).Sum(),

                StateOfPreparation = regionAnnualReportQuestions.StateOfPreparation,

                Characteristic = regionAnnualReportQuestions.Characteristic,

                ChurchCooperation = regionAnnualReportQuestions.ChurchCooperation,

                InvolvementOfVolunteers = regionAnnualReportQuestions.InvolvementOfVolunteers,

                ImportantNeeds = regionAnnualReportQuestions.ImportantNeeds,

                SocialProjects = regionAnnualReportQuestions.SocialProjects,

                StatusOfStrategy = regionAnnualReportQuestions.StatusOfStrategy,

                SuccessStories = regionAnnualReportQuestions.SuccessStories,

                ProblemSituations = regionAnnualReportQuestions.ProblemSituations,

                TrainedNeeds = regionAnnualReportQuestions.TrainedNeeds,

                PublicFunding = regionAnnualReportQuestions.PublicFunding,

                Fundraising = regionAnnualReportQuestions.Fundraising
            };

            _repositoryWrapper.RegionAnnualReports.Create(regionAnnualReport);
            await _repositoryWrapper.SaveAsync();

            return(_mapper.Map <RegionAnnualReportDTO>(regionAnnualReport));
        }
        ///<inheritdoc/>
        public async Task <RegionAnnualReportDTO> CreateByNameAsync(User claimsPrincipal, int id, int year,
                                                                    RegionAnnualReportQuestions regionAnnualReportQuestions)
        {
            var region = await _repositoryWrapper.Region.GetFirstOrDefaultAsync(a => a.ID == id);

            if (!await _regionAccessService.HasAccessAsync(claimsPrincipal, region.ID))
            {
                throw new UnauthorizedAccessException("User doesn't have access");
            }

            if (await CheckCreatedAsync(id, year))
            {
                throw new InvalidOperationException("Report is already created!");
            }

            DateTime reportDate;

            if (year == DateTime.Now.Year)
            {
                reportDate = DateTime.Now;
            }
            else
            {
                reportDate = new DateTime(year, 12, 31);
            }

            var regionAnnualReport = new RegionAnnualReport()
            {
                RegionName = region.RegionName,

                RegionId = id,

                Date = reportDate,

                StateOfPreparation = regionAnnualReportQuestions.StateOfPreparation,

                Characteristic = regionAnnualReportQuestions.Characteristic,

                ChurchCooperation = regionAnnualReportQuestions.ChurchCooperation,

                InvolvementOfVolunteers = regionAnnualReportQuestions.InvolvementOfVolunteers,

                ImportantNeeds = regionAnnualReportQuestions.ImportantNeeds,

                SocialProjects = regionAnnualReportQuestions.SocialProjects,

                StatusOfStrategy = regionAnnualReportQuestions.StatusOfStrategy,

                SuccessStories = regionAnnualReportQuestions.SuccessStories,

                ProblemSituations = regionAnnualReportQuestions.ProblemSituations,

                TrainedNeeds = regionAnnualReportQuestions.TrainedNeeds,

                PublicFunding = regionAnnualReportQuestions.PublicFunding,

                Fundraising = regionAnnualReportQuestions.Fundraising
            };

            regionAnnualReport = await SetMembersInfoAsync(regionAnnualReport);

            _repositoryWrapper.RegionAnnualReports.Create(regionAnnualReport);
            await _repositoryWrapper.SaveAsync();

            return(_mapper.Map <RegionAnnualReportDTO>(regionAnnualReport));
        }