< Summary

Class:WinSolutions.Sveta.Server.Services.Implements.IncidentService
Assembly:WinSolutions.Sveta.Server
File(s):/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/IncidentService.cs
Covered lines:18
Uncovered lines:0
Coverable lines:18
Total lines:55
Line coverage:100% (18 of 18)
Covered branches:5
Total branches:10
Branch coverage:50% (5 of 10)

Metrics

MethodLine coverage Branch coverage
.ctor(...)100%100%
CreateIncident()100%50%
GetKindType()100%100%
GetStatusType()100%100%

File(s)

/opt/dev/sveta_api_build/WinSolutions.Sveta.Server/Services/Implements/IncidentService.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.Extensions.Logging;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Threading.Tasks;
 6using WinSolutions.Sveta.Server.Data.DataModel.Contexts;
 7using WinSolutions.Sveta.Server.Data.DataModel.Entities;
 8using WinSolutions.Sveta.Server.Services.Interfaces;
 9using WinSolutions.Sveta.Common;
 10using System;
 11
 12namespace WinSolutions.Sveta.Server.Services.Implements
 13{
 14    public class IncidentService : SvetaServiceBase, IIncidentService
 15    {
 16        private readonly SvetaDbContext _db;
 17        private readonly ILogger<IncidentService> _logger;
 18        public IncidentService(SvetaDbContext db, ILogger<IncidentService> logger, IAuthenticationService authentication
 119            : base(authenticationService)
 120        {
 121            _db = db;
 122            _logger = logger;
 123        }
 24
 25        /// <summary>
 26        ///  создает инцидент
 27        /// </summary>
 28        /// <param name="incident">Инцидент</param>
 29        /// <returns></returns>
 30        public async Task CreateIncident(Incident incident)
 131        {
 132            _db.Entry(incident.Kind).State = incident.Kind.Id == 0 ? EntityState.Detached : EntityState.Unchanged;
 133            _db.Entry(incident.User).State = incident.User.Id == 0 ? EntityState.Detached : EntityState.Unchanged;
 134            _db.Entry(incident.Status).State = incident.Status.Id == 0 ? EntityState.Detached : EntityState.Unchanged;
 135            await _db.Incidents.AddAsync(incident);
 136            await _db.SaveChangesAsync(CurrentUserId);
 137        }
 38
 39        /// <summary>
 40        /// получить типы инцидента
 41        /// </summary>
 42        /// <returns></returns>
 143        public async Task<List<IncidentsKind>> GetKindType() => await _db.refIncidentsKind
 144            .Where(e => !e.IsDeleted)
 145            .ToListAsync();
 46
 47        /// <summary>
 48        /// получить статусы инцидента
 49        /// </summary>
 50        /// <returns></returns>
 151        public async Task<List<IncidentsStatus>> GetStatusType() => await _db.refIncidentsStatus
 152           .Where(e => !e.IsDeleted)
 153           .ToListAsync();
 54    }
 55}