Advertisement
parabola949

Linq and EntityFramework

Jul 8th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. //GETTING DATA
  2. db = new CM_PS1Context();
  3.             var software = (from c in db.Collections
  4.                 join d in db.v_DeploymentSummary on c.SiteID equals d.CollectionID
  5.                 join q in db.v_CollectionRuleQuery on d.CollectionID equals q.CollectionID
  6.                 join p in db.v_Package on d.PackageID equals p.PackageID
  7.                 where q.QueryExpression.Contains("ECHRISTUS") && !d.CollectionName.Contains("Limiting Collection") &&
  8.                     !d.CollectionName.Contains("group test")
  9.  
  10.                 orderby c.CollectionName
  11.  
  12.                 select
  13.                     new Software()
  14.                     {
  15.                         Name = c.CollectionName,
  16.                         Group =
  17.                             q.QueryExpression.Substring(q.QueryExpression.IndexOf("ECHRISTUS\\"))
  18.                                 .Replace("ECHRISTUS\\", "")
  19.                     }
  20.                     ).ToList().Distinct(new SoftwareComparer());
  21.             var result = new BindableCollection<Software>();
  22.             foreach (var s in software)
  23.             {
  24.                 s.Group = s.Group.Substring(0, s.Group.IndexOf('\''));
  25.                 //validate the group, some are wrong
  26.                 if (GroupPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), s.Group) != null)
  27.                     result.Add(new Software {Name = s.Name, Group = s.Group});
  28.             }
  29.             return result;
  30.  
  31.  
  32. //INSERTING DATA
  33.  
  34. public static void AddEvent(Event e, string user, string source, string destination)
  35.         {
  36.             //Validate the database has been initialized
  37.             using (var db = new AuditContext())
  38.             {
  39.                 db.Database.Connection.Open();
  40.                 var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  41.  
  42.                 db.AuditLogs.Add(new AuditLog
  43.                 {
  44.                     UserID = user,
  45.                     DestPC = destination,
  46.                     SourcePC = source,
  47.                     Timestamp = DateTime.Now,
  48.                     Action = e.ToString(),
  49.                     AppVersion = version
  50.                 });
  51.                 db.SaveChanges();
  52.             }
  53.  
  54.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement