private async Task <IEnumerable <DotnetAppDotnetNugets> > GetDotnetAppsDotnetNugets()
 {
     using (var context = new PikapikaContext(_options))
     {
         return(await context.DotnetAppDotnetNugets.ToListAsync());
     }
 }
        private void SaveDotnetNuget(DotnetNugets dotnetNuget, IEnumerable <DotnetNugets> storedDotnetNugets)
        {
            var storedDotnetNuget = storedDotnetNugets
                                    .Where(x =>
                                           x.Slug == dotnetNuget.Slug)
                                    .FirstOrDefault();

            using (var context = new PikapikaContext(_options))
            {
                if (storedDotnetNuget != null)
                {
                    if (storedDotnetNuget.UpdatedAt == dotnetNuget.UpdatedAt)
                    {
                        _logger.LogInformation($"Nuget {dotnetNuget.Name} did not change, no db operation for this nuget.");
                        return;
                    }

                    _logger.LogInformation($"Nuget {dotnetNuget.Name} needs updating.");
                    dotnetNuget.Id = storedDotnetNuget.Id;
                    context.DotnetNugets.Update(dotnetNuget);
                }
                else
                {
                    _logger.LogInformation($"Nuget {dotnetNuget.Name} is new.");
                    context.DotnetNugets.Add(dotnetNuget);
                }
                context.SaveChanges();
            }
        }
        private void SaveDotnetAppDotnetNugetRelationship(DotnetAppDotnetNugets dotnetAppDotnetNuget, IEnumerable <DotnetAppDotnetNugets> storedDotnetAppDotnetNugets)
        {
            var storedDotnetAppDotnetNuget = storedDotnetAppDotnetNugets
                                             .Where(x =>
                                                    x.DotnetAppId.Value == dotnetAppDotnetNuget.DotnetAppId.Value &&
                                                    x.DotnetNugetId.Value == dotnetAppDotnetNuget.DotnetNugetId.Value)
                                             .FirstOrDefault();

            using (var context = new PikapikaContext(_options))
            {
                if (storedDotnetAppDotnetNuget != null)
                {
                    if (storedDotnetAppDotnetNuget.Version == dotnetAppDotnetNuget.Version)
                    {
                        _logger.LogInformation($"DotnetAppDotnetNugetRelationship AppId:{dotnetAppDotnetNuget.DotnetAppId}, NugetId: {dotnetAppDotnetNuget.DotnetNugetId} did not change.");
                        return;
                    }

                    _logger.LogInformation($"DotnetAppDotnetNugetRelationship AppId:{dotnetAppDotnetNuget.DotnetAppId}, NugetId: {dotnetAppDotnetNuget.DotnetNugetId} needs updating.");
                    dotnetAppDotnetNuget.Id = storedDotnetAppDotnetNuget.Id;
                    context.DotnetAppDotnetNugets.Update(dotnetAppDotnetNuget);
                }
                else
                {
                    _logger.LogInformation($"DotnetAppDotnetNugetRelationship AppId:{dotnetAppDotnetNuget.DotnetAppId}, NugetId: {dotnetAppDotnetNuget.DotnetNugetId} is new.");
                    context.DotnetAppDotnetNugets.Add(dotnetAppDotnetNuget);
                }
                context.SaveChanges();
            }
        }
        private async Task <DotnetApps> SaveDotnetApp(DotnetApps dotnetApp)
        {
            var existingDotnetApp = await GetDotnetApp(dotnetApp.Repo, dotnetApp.Path);

            if (await HasDuplicateDotnetApp(dotnetApp.Name, dotnetApp.Repo, dotnetApp.Path))
            {
                dotnetApp.Name = ($"{dotnetApp.Repo.Replace("mdsol/", string.Empty)}_{dotnetApp.Name}").Replace(".csproj", string.Empty);
            }

            using (var context = new PikapikaContext(_options))
            {
                if (existingDotnetApp != null)
                {
                    dotnetApp.Id = existingDotnetApp.Id;
                    context.DotnetApps.Update(dotnetApp);
                }
                else
                {
                    context.DotnetApps.Add(dotnetApp);
                }
                context.SaveChanges();
            }

            return(dotnetApp);
        }
 public async Task <IEnumerable <DotnetApps> > GetDotnetApps()
 {
     using (var context = new PikapikaContext(_options))
     {
         return(await context.DotnetApps.ToListAsync());
     }
 }
        private void DeleteDotnetAppNugetRelationship(DotnetAppDotnetNugets dotnetAppDotnetNugets)
        {
            using (var context = new PikapikaContext(_options))
            {
                context.Entry(dotnetAppDotnetNugets).State = EntityState.Deleted;

                context.SaveChanges();
            }
        }
 public async Task <DotnetApps> GetDotnetApp(string repo, string path)
 {
     using (var context = new PikapikaContext(_options))
     {
         return(await context.DotnetApps
                .Where(x =>
                       repo == x.Repo &&
                       path == x.Path)
                .FirstOrDefaultAsync());
     }
 }
 public async Task <bool> HasDuplicateDotnetApp(string name, string repo, string path)
 {
     using (var context = new PikapikaContext(_options))
     {
         var idCombination = $"{repo}{path}";
         return((await context.DotnetApps
                 .Where(x =>
                        name == x.Name &&
                        idCombination != x.Repo + x.Path)
                 .FirstOrDefaultAsync()) != null);
     }
 }
        private async Task DeleteDotnetApp(DotnetApps dotnetApp)
        {
            using (var context = new PikapikaContext(_options))
            {
                foreach (var reference in await context.DotnetAppDotnetNugets
                         .Where(reference => reference.DotnetAppId == dotnetApp.Id).ToListAsync())
                {
                    context.Entry(reference).State = EntityState.Deleted;
                }
                context.Entry(dotnetApp).State = EntityState.Deleted;

                context.SaveChanges();
            }
        }
        public async Task <IEnumerable <DotnetApps> > GetDotnetApps(IEnumerable <DotnetApps> apps)
        {
            using (var context = new PikapikaContext(_options))
            {
                var allApps = await context.DotnetApps
                              .ToListAsync();

                return(allApps
                       .Where(x =>
                              apps.Any(y =>
                                       y.Repo == x.Repo &&
                                       y.Path == x.Path)));
            }
        }