コード例 #1
0
ファイル: UserRepo.cs プロジェクト: nik0301/If-Safety-Fund
 public virtual int GetUserCount()
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Users.Count());
     }
 }
コード例 #2
0
 public virtual TEntity Get(TIdentity id)
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Set <TEntity>().Find(id));
     }
 }
コード例 #3
0
 public virtual IList <TEntity> Get()
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Set <TEntity>().ToList());
     }
 }
コード例 #4
0
 public virtual int GetVotesCountByProject(int projectId)
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Votes.Count(item => item.ProjectId == projectId));
     }
 }
コード例 #5
0
 public virtual bool IsCountryAllowed(string country)
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Locations.Any(item => item.Country == country));
     }
 }
コード例 #6
0
ファイル: ProjectRepo.cs プロジェクト: nik0301/If-Safety-Fund
 public virtual List <Project> GetByCampaign(int campaignId)
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         return(db.Projects.Where(project => project.CampaignId == campaignId).ToList());
     }
 }
コード例 #7
0
 public virtual void Delete(TEntity entity)
 {
     using (var db = new SafetyFundDbContext(Options))
     {
         db.Set <TEntity>().Remove(entity);
         db.SaveChanges();
     }
 }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
        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));
            }
        }
コード例 #10
0
 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));
     }
 }
コード例 #11
0
ファイル: ProjectRepo.cs プロジェクト: nik0301/If-Safety-Fund
        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());
            }
        }
コード例 #12
0
        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());
            }
        }