Summary

Class:ProjectX.Ef.Stores.EventStore
Assembly:ProjectX.Ef
File(s):C:\private\projects\projectx\backend\src\ProjectX.Ef\Stores\EventStore.cs
Covered lines:38
Uncovered lines:5
Coverable lines:43
Total lines:94
Line coverage:88.3%

History

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor(...)10100100
LoadEventByIdAsync()10100100
CreateEventAsync()50100100
UpdateEventAsync()3000
LoadEventsAsync()10100100
DeleteEventAsync()3000

File(s)

C:\private\projects\projectx\backend\src\ProjectX.Ef\Stores\EventStore.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Threading.Tasks;
 4using Microsoft.EntityFrameworkCore;
 5using ProjectX.Entities;
 6using ProjectX.Models;
 7using ProjectX.Stores;
 8
 9namespace ProjectX.Ef.Stores
 10{
 11    public class EventStore : IEventStore
 12    {
 13        private readonly MainDbContext _dbContext;
 14
 815        public EventStore(MainDbContext dbContext)
 16        {
 817            this._dbContext = dbContext;
 818        }
 19
 20        public async Task<Event> LoadEventByIdAsync(Guid eventId)
 21        {
 522            var result = this._dbContext.Events.AsNoTracking()
 523                .Where(c =>
 524                    c.DeletedAt == null &&
 525                    c.Id.Equals(eventId) &&
 526                    c.Participants.Any(x =>
 527                        x.User.DeletedAt == null
 528                    )
 529                )
 530                .Include(c => c.Participants)
 531                .Include("Participants.User")
 532                .FirstOrDefault();
 33
 534            return result;
 535        }
 36
 37        public async Task<Event> CreateEventAsync(Event evnt)
 38        {
 139            await this._dbContext.Events.AddAsync(evnt);
 40
 41            // TODO: move to some abstraction
 142            await this._dbContext.SaveChangesAsync();
 43
 144            return evnt;
 145        }
 46
 47        public async Task<Event> UpdateEventAsync(Event evnt)
 48        {
 049            this._dbContext.Events.Attach(evnt);
 50
 51            // TODO: move to some abstraction
 052            await this._dbContext.SaveChangesAsync();
 53
 054            return evnt;
 55        }
 56
 57        public async Task<PagedList<Event>> LoadEventsAsync(
 58            Guid userId,
 59            DateTime dateFrom,
 60            double latitude,
 61            double longitude,
 62            int perimeter = 50,
 63            int ageFrom = 16,
 64            int ageTo = 100,
 65            int take = 10,
 66            int skip = 0)
 67        {
 268            var q = this._dbContext.Events.AsNoTracking()
 269                .Where(c =>
 270                    c.DeletedAt == null &&
 271                    //c.CreatedBy.Age >= ageFrom &&
 272                    //c.CreatedBy.Age <= ageTo &&
 273                    c.Participants.Any(x =>
 274                        x.User.DeletedAt == null &&
 275                        x.User.Id.Equals(userId)
 276                    )
 277                )
 278                .Include("Participants.User");
 79
 280            return new PagedList<Event>(
 281                items: q.Take(take).Skip(skip).ToArray(),
 282                total: q.Count(),
 283                skip: skip,
 284                take: take
 285            );
 286        }
 87
 88        public async Task DeleteEventAsync(Event evnt)
 89        {
 090            this._dbContext.Remove(evnt);
 091            await this._dbContext.SaveChangesAsync();
 92        }
 93    }
 94}