示例#1
0
 public IEnumerable <CountryInfo> GetCountryInfos()
 {
     using (var dbContext = new HappyDbContext())
     {
         List <CountryInfo> countryInfoList = dbContext.Database.SqlQuery <CountryInfo>("GetCounties").ToList();
         return(countryInfoList);
     }
 }
示例#2
0
 public void ClearVotes(string countryId)
 {
     using (var dbContext = new HappyDbContext())
     {
         dbContext.CountryVotes.RemoveRange(dbContext.CountryVotes.Where(x => x.CountryId == countryId));
         dbContext.SaveChanges();
     }
 }
示例#3
0
 public void ClearAllVotes()
 {
     using (var dbContext = new HappyDbContext())
     {
         dbContext.CountryVotes.RemoveRange(dbContext.CountryVotes);
         dbContext.SaveChanges();
     }
 }
示例#4
0
 public void AddCountryVote(CountryVoteRequest countryVoteRequest)
 {
     using (var dbContext = new HappyDbContext())
     {
         dbContext.CountryVotes.Add(new CountryVote()
         {
             Id           = Guid.NewGuid(),
             Rate         = countryVoteRequest.Rate,
             CountryId    = countryVoteRequest.CountryId,
             IsInhabitant = countryVoteRequest.IsInhabitant,
         });
         dbContext.SaveChanges();
     }
 }
示例#5
0
        public IEnumerable <IndexInfo> GetCountryTextInfo(string countryId)
        {
            using (var dbContext = new HappyDbContext())
            {
                List <Models.Data.IndexInfo> countryIndexInfoList = dbContext.IndexInfos.Where(x => x.CountryId == countryId).ToList();

                return(from c in IndexContacts.DefaultIndexInfo
                       join ci in countryIndexInfoList on c.Name equals ci.Name into _ci
                       from ci in _ci.DefaultIfEmpty()
                       select new IndexInfo
                {
                    Name = c.Name,
                    Details = ci == null ? c.Details : ci.Details,
                    Text = ci == null ? c.Text : ci.Text,
                    WaysToImprove = ci == null ? c.WaysToImprove : ci.WaysToImprove,
                });
            }
        }