public Models.User Get(Models.User dummy) { var entity = SiteDbContext.CreateDbContext().SiteUsers .Where(it => it.SiteName == dummy.Site.FullName && it.UserName == dummy.UserName) .FirstOrDefault(); return(entity == null ? null : SiteUserHelper.ToUser(entity)); }
public IEnumerable <Models.User> All(Models.Site site) { return(SiteDbContext.CreateDbContext().SiteUsers .Where(it => it.SiteName == site.FullName) .ToArray() .Select(it => SiteUserHelper.ToUser(it)) .AsQueryable()); }
private void InsertOrUpdate(Models.User @new, Models.User old) { var dbContext = SiteDbContext.CreateDbContext(); var entity = dbContext.SiteUsers .Where(it => it.SiteName == @new.Site.FullName && it.UserName == @new.UserName) .FirstOrDefault(); if (entity != null) { entity = SiteUserHelper.ToEntity(@new, entity); } else { entity = entity = SiteUserHelper.ToEntity(@new, entity); dbContext.SiteUsers.Add(entity); } dbContext.SaveChanges(); }