< Summary

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

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
CreateProject(...)0%40%
GetDashboardInfo(...)100%10%
.ctor(...)100%10%

File(s)

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

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using MUNity.Database.Models.Conference;
 3using MUNity.Schema.Project;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Text;
 8using System.Threading.Tasks;
 9
 10namespace MUNity.Services
 11{
 12    public class ProjectService
 13    {
 14        private readonly MUNity.Database.Context.MunityContext context;
 15
 16        public CreateProjectResponse CreateProject(CreateProjectModel model)
 017        {
 018            var response = new CreateProjectResponse();
 19
 20            // TODO: Check user is allowed to create projects!
 21
 022            var organization = context.Organizations.FirstOrDefault(n => n.OrganizationId == model.OrganizationId);
 023            if (organization == null)
 024            {
 025                response.Status = CreateProjectResponse.CreateProjectStatus.OrganizationNotFound;
 026                return response;
 27            }
 28
 29
 030            var project = new Project()
 031            {
 032                ProjectName = model.Name,
 033                ProjectShort = model.Short,
 034                ProjectOrganization = organization
 035            };
 36
 037            string cleanedId = Util.IdGenerator.AsPrimaryKey(model.Short);
 038            if (context.Projects.All(n => n.ProjectId != cleanedId))
 039                project.ProjectId = cleanedId;
 40
 041            context.Projects.Add(project);
 042            context.SaveChanges();
 043            response.ProjectId = project.ProjectId;
 044            return response;
 045        }
 46
 47        public ProjectDashboardInfo GetDashboardInfo(string projectId)
 048        {
 049            return context.Projects.AsNoTracking()
 050                .Select(n => new ProjectDashboardInfo()
 051                {
 052                    Name = n.ProjectName,
 053                    Short = n.ProjectShort,
 054                    ProjectId = n.ProjectId,
 055                    Conferences = n.Conferences.Select(a => new ProjectDashboardConferenceInfo()
 056                    {
 057                        ConferenceId = a.ConferenceId,
 058                        EndDate = a.EndDate,
 059                        Name = a.Name,
 060                        FullName = a.FullName,
 061                        Short = a.ConferenceShort,
 062                        StartDate = a.StartDate,
 063                        CreationDate = a.CreationDate,
 064                        CreationUserUsername = a.CreationUser.UserName
 065                    }).ToList()
 066                })
 067                .FirstOrDefault(n => n.ProjectId == projectId);
 068        }
 69
 070        public ProjectService(Database.Context.MunityContext context)
 071        {
 072            this.context = context;
 073        }
 74    }
 75}