< Summary

Class:MUNity.Services.ConferenceApplicationService
Assembly:MUNity.Services
File(s):C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityServices\Services\ConferenceApplicationService.cs
Covered lines:0
Uncovered lines:68
Coverable lines:68
Total lines:124
Line coverage:0% (0 of 68)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)
Covered methods:0
Total methods:4
Method coverage:0% (0 of 4)

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AvailableDelegations(...)0%40%
FindUserToAddToDelegationApplication(...)0%60%
GetApplicationsOfUser(...)100%10%
.ctor(...)100%10%

File(s)

C:\Users\aeuke\source\repos\PeerConradi\munity\src\MUNityServices\Services\ConferenceApplicationService.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.Extensions.Logging;
 3using MUNity.Database.Context;
 4using MUNity.Database.Models.Conference;
 5using MUNity.Schema.Conference;
 6using System;
 7using System.Collections.Generic;
 8using System.Linq;
 9using System.Security.Claims;
 10using System.Text;
 11using System.Threading.Tasks;
 12
 13namespace MUNity.Services
 14{
 15    public class ConferenceApplicationService
 16    {
 17        private MunityContext _dbContext;
 18
 19        private ILogger<ConferenceApplicationService> _logger;
 20
 21        public enum AvailableDelegationsTypes
 22        {
 23            All,
 24            OnlineOnly,
 25            PresenceOnly
 26        }
 27
 28        public List<ApplicationAvailableDelegation> AvailableDelegations(string conferenceId, int minRolesCount = 1, Ava
 029        {
 30            IQueryable<Delegation> delegationsQuery;
 31
 032            switch (type)
 33            {
 34                case AvailableDelegationsTypes.All:
 035                    throw new NotImplementedException();
 36                case AvailableDelegationsTypes.OnlineOnly:
 037                    delegationsQuery = _dbContext.Fluent.ForConference(conferenceId)
 038                .DelegationsWithOnlyOnlineRoles();
 039                    break;
 40                case AvailableDelegationsTypes.PresenceOnly:
 041                    delegationsQuery = _dbContext.Fluent.ForConference(conferenceId)
 042                .DelegationsWithOnlyAtLocationSlots();
 043                    break;
 44                default:
 045                    throw new NotImplementedException();
 46            }
 47
 048            return delegationsQuery.Select(n => new ApplicationAvailableDelegation()
 049                {
 050                    DelegationId = n.DelegationId,
 051                    Name = n.Name,
 052                    Roles = n.Roles.Select(role => new ApplicationDelegationRoleSlot()
 053                    {
 054                        CommitteeName = role.Committee.Name,
 055                        Costs = _dbContext.Fluent.ForConference(conferenceId).GetCostOfRole(role.RoleId),
 056                        RoleName = role.RoleName,
 057                        CountryName = role.DelegateCountry.Name,
 058                        CountryIso = role.DelegateCountry.Iso
 059                    }).ToList()
 060                }).Where(n => n.Roles.Count >= minRolesCount).ToList();
 061        }
 62
 63        public FindUserForApplicationResult FindUserToAddToDelegationApplication(string mailOrUsername, string conferenc
 064        {
 065            var normalized = mailOrUsername.ToUpper();
 066            var user = _dbContext.Users.FirstOrDefault(n => n.NormalizedUserName == normalized || n.NormalizedEmail == n
 067            if (user != null)
 068            {
 69                // Check if user is already participating
 070                var alreadyParticipating = _dbContext.Participations.Any(n => n.User.Id == user.Id && n.Role.Conference.
 071                if (alreadyParticipating)
 072                    return new FindUserForApplicationResult() { Status = FindUserForApplicationResult.ResultStatuses.Alr
 73
 74                // Check user already in an application
 075                var alreadyApplying = _dbContext.DelegationApplicationUserEntries
 076                    .Any(n => n.User.Id == user.Id && n.Application.DelegationWishes
 077                        .Any(a => a.Delegation.Conference.ConferenceId == conferenceId));
 078                if (alreadyApplying)
 079                    return new FindUserForApplicationResult() { Status = FindUserForApplicationResult.ResultStatuses.Alr
 80
 81                // Return the user and ok
 082                return new FindUserForApplicationResult()
 083                {
 084                    Status = FindUserForApplicationResult.ResultStatuses.CanBeAdded,
 085                    ForeName = user.Forename,
 086                    LastName = user.Lastname,
 087                    UserName = user.UserName
 088                };
 89            }
 90            else
 091            {
 92                // Return user doesnt exists result
 093                return new FindUserForApplicationResult() { Status = FindUserForApplicationResult.ResultStatuses.NoUserF
 94            }
 095        }
 96
 97        public List<UserApplicationInfo> GetApplicationsOfUser(ClaimsPrincipal claim)
 098        {
 099            var list = new List<UserApplicationInfo>();
 100
 0101            var delegationApplications = _dbContext.DelegationApplicationUserEntries
 0102                .Where(n => n.User.NormalizedUserName == claim.Identity.Name.ToUpper())
 0103                .Include(n => n.Application)
 0104                .AsNoTracking()
 0105                .Select(n => new UserApplicationInfo()
 0106                {
 0107                    ApplicationId = n.Application.DelegationApplicationId,
 0108                    ConferenceFullName = n.Application.Conference.FullName,
 0109                    ConferenceId = n.Application.Conference.ConferenceId,
 0110                    ConferenceName = n.Application.Conference.Name,
 0111                    ConferenceShort = n.Application.Conference.ConferenceShort
 0112                });
 113
 114
 0115            return delegationApplications.ToList();
 0116        }
 117
 0118        public ConferenceApplicationService(MunityContext context, ILogger<ConferenceApplicationService> logger)
 0119        {
 0120            this._dbContext = context;
 0121            this._logger = logger;
 0122        }
 123    }
 124}