public virtual int GetUserCount() { using (var db = new SafetyFundDbContext(Options)) { return(db.Users.Count()); } }
public virtual TEntity Get(TIdentity id) { using (var db = new SafetyFundDbContext(Options)) { return(db.Set <TEntity>().Find(id)); } }
public virtual IList <TEntity> Get() { using (var db = new SafetyFundDbContext(Options)) { return(db.Set <TEntity>().ToList()); } }
public virtual int GetVotesCountByProject(int projectId) { using (var db = new SafetyFundDbContext(Options)) { return(db.Votes.Count(item => item.ProjectId == projectId)); } }
public virtual bool IsCountryAllowed(string country) { using (var db = new SafetyFundDbContext(Options)) { return(db.Locations.Any(item => item.Country == country)); } }
public virtual List <Project> GetByCampaign(int campaignId) { using (var db = new SafetyFundDbContext(Options)) { return(db.Projects.Where(project => project.CampaignId == campaignId).ToList()); } }
public virtual void Delete(TEntity entity) { using (var db = new SafetyFundDbContext(Options)) { db.Set <TEntity>().Remove(entity); db.SaveChanges(); } }
public virtual void Update(TEntity entity) { using (var db = new SafetyFundDbContext(Options)) { db.Set <TEntity>().Attach(entity); db.Entry(entity).State = EntityState.Modified; db.SaveChanges(); } }
public virtual Campaign GetNewestCampaign() { using (var db = new SafetyFundDbContext(Options)) { var campaignsOrderedByEndTime = db.Campaigns.OrderByDescending(item => item.EndDateTime); var lastActiveCampaign = campaignsOrderedByEndTime.First(item => item.EndDateTime > DateTime.Now && item.StartDateTime <= DateTime.Now); return(lastActiveCampaign ?? campaignsOrderedByEndTime.First(item => item.StartDateTime < DateTime.Now)); } }
public virtual bool HasUserVotedToday(string userId, int projectId, string socialName) { using (var db = new SafetyFundDbContext(Options)) { return(db.Votes.Any(item => item.UserId == userId && item.ProjectId == projectId && item.VotingDateTime.Date == DateTime.Today && item.SocialName == socialName)); } }
public virtual List <ProjectReport> GetProjectsReport(int campaignId) { using (var db = new SafetyFundDbContext(Options)) { var query = from project in db.Projects where project.CampaignId == campaignId join vote in db.Votes on project.Id equals vote.ProjectId into v from joinedVote in v.DefaultIfEmpty() group joinedVote by project into projectGroup select new ProjectReport { Project = projectGroup.Key, Votes = projectGroup.Count(p => p != null) }; return(query.ToList()); } }
public virtual List <CampaignReport> GetCampaignsAndProjectCounts() { using (var db = new SafetyFundDbContext(Options)) { var query = from campaign in db.Campaigns join project in db.Projects on campaign.Id equals project.CampaignId into proj from joinedProject in proj.DefaultIfEmpty() orderby campaign.EndDateTime descending group joinedProject by campaign into campaignGroup select new CampaignReport() { Campaign = campaignGroup.Key, ProjectCount = campaignGroup.Count(p => p != null) }; return(query.ToList()); } }