public static void DeleteContributions(this BikeDataDbContext dbContext, List <Contribution> contributions, List <UserContribution> userContributions)
        {
            dbContext.UserContributions.RemoveRange(userContributions);
            dbContext.Contributions.RemoveRange(contributions);

            dbContext.SaveChanges();
        }
예제 #2
0
 public Startup(BikeDataDbContext db)
 {
     _db = db;
 }
 public static int GetTotalDistance(this BikeDataDbContext dbContext)
 {
     return(dbContext.Contributions.Select(c => c.Distance).Sum());
 }
 public static void SaveChanges(this BikeDataDbContext dbContext) => dbContext.SaveChanges();
 public static IEnumerable <UserContribution> GetUserContributionsByContributionIds(this BikeDataDbContext dbContext, IEnumerable <int> contributionIds)
 {
     return(dbContext.UserContributions.Where(uc => contributionIds.Contains(uc.ContributionId)));
 }
 public static IEnumerable <int> GetContributionsIds(this BikeDataDbContext dbContext, int userIdentifier)
 {
     return(dbContext.UserContributions.Where(uc => uc.UserId == userIdentifier).Select(uc => uc.ContributionId));
 }
 public static void AddUser(this BikeDataDbContext dbContext, User user)
 {
     dbContext.Users.Add(user);
 }
 public static User ContainsProviderUser(this BikeDataDbContext dbContext, string providerUser)
 {
     return(dbContext.Users.FirstOrDefault(u => u.ProviderUser == providerUser));
 }
 public static void AddUserContribution(this BikeDataDbContext dbContext, UserContribution userContribution)
 {
     dbContext.UserContributions.Add(userContribution);
 }
 public static void AddContribution(this BikeDataDbContext dbContext, Contribution contribution)
 {
     dbContext.Contributions.Add(contribution);
 }
        public static int GetUserId(this BikeDataDbContext dbContext, Guid userId)
        {
            var user = dbContext.Users.FirstOrDefault(u => u.UserIdentifier == userId);

            return(user != null ? user.Id : 0);
        }