public static WatchDog Load(int watchdogId) { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { return(db.WatchDogs.Where(m => m.Id == watchdogId).FirstOrDefault()); } }
public static IEnumerable <PerStrana> AllSponsored() { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { PerStrana[] oSponzori = db.OsobaEvent .Where(t => t.Type == (int)HlidacStatu.Lib.Data.OsobaEvent.Types.Sponzor) .GroupBy(g => g.AddInfo, e => e, (k, e) => new PerStrana() { Strana = k, Num = e.Count(), Sum = e.Sum(s => s.AddInfoNum) ?? 0 }) .ToArray() ; //.Select(m => new Tuple<string, int, int>(m.strana, m.pocet, 0)); PerStrana[] fSponzori = db.FirmaEvent .Where(t => t.Type == (int)HlidacStatu.Lib.Data.FirmaEvent.Types.Sponzor) .GroupBy(g => g.AddInfo, e => e, (k, e) => new PerStrana() { Strana = k, Num = e.Count(), Sum = e.Sum(s => s.AddInfoNum) ?? 0 }) .ToArray() ; //.Select(m => new Tuple<string, int, int>(m.strana, 0, m.pocet)); var sponzori = oSponzori .FullOuterJoin(fSponzori, o => o.Strana, f => f.Strana, (o, f, k) => new PerStrana() { Strana = k, Num = f?.Num ?? 0 + o?.Num ?? 0, Sum = f?.Sum ?? 0 + o?.Sum ?? 0 }) //.GroupBy(g => g.Item1, e => e, (k, e) => new { strana = k, pocet = e.Sum(sum=>sum.Item2) }) .OrderBy(o => o.Strana) .ToArray(); return(sponzori); } }
public static AspNetUser GetByEmail(string email) { if (string.IsNullOrEmpty(email)) { return(null); } using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { return(db.AspNetUsers.AsNoTracking().FirstOrDefault(m => m.Email == email)); } }
public static void DeleteBookmark(ItemTypes type, string itemId, string userId) { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { var b = db.Bookmark.FirstOrDefault(m => m.ItemType == (int)type && m.ItemId == itemId && m.UserId == userId); if (b != null) { db.Bookmark.Remove(b); db.SaveChanges(); } } }
public static bool IsItemBookmarked(ItemTypes type, string itemId, string userId) { if (string.IsNullOrEmpty(userId)) { return(false); } using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { return(db.Bookmark.Any(m => m.ItemType == (int)type && m.ItemId == itemId && m.UserId == userId)); } }
public void Delete() { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { if (this.Id == 0) { } else { db.WatchDogs.Attach(this); db.Entry(this).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); } } }
public void Save() { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { if (this.Id == default(Guid)) { this.Id = Guid.NewGuid(); db.Bookmark.Add(this); } else { db.Bookmark.Attach(this); db.Entry(this).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); } }
public static IEnumerable <StranaPerYear> PerYears(string strana) { using (HlidacStatu.Lib.Data.DbEntities db = new HlidacStatu.Lib.Data.DbEntities()) { var resultO = db.OsobaEvent .Where(m => m.AddInfo == strana && m.Type == 3 && m.DatumOd.HasValue) .ToArray() .Select(m => new { rok = m.DatumOd.Value.Year, oe = m }) .GroupBy(g => g.rok, oe => oe.oe, (r, oe) => new StranaPerYear() { Rok = r, Osoby = new AggSum() { Num = oe.Count(), Sum = oe.Sum(s => s.AddInfoNum) ?? 0 } }); var resultF = db.FirmaEvent .Where(m => m.AddInfo == strana && m.Type == 3 && m.DatumOd.HasValue) .ToArray() .Select(m => new { rok = m.DatumOd.Value.Year, oe = m }) .GroupBy(g => g.rok, oe => oe.oe, (r, oe) => new StranaPerYear() { Rok = r, Firmy = new AggSum() { Num = oe.Count(), Sum = oe.Sum(s => s.AddInfoNum) ?? 0 } }); var roky = resultO.FullOuterJoin(resultF, o => o.Rok, f => f.Rok, (o, f, k) => new StranaPerYear() { Strana = strana, Rok = k, Osoby = o?.Osoby ?? new AggSum(), Firmy = f?.Firmy ?? new AggSum() }); return(roky); } }