예제 #1
0
 public Dialogue CreateDialogue(List <string> usernames, string me)
 {
     usernames = usernames.Concat(new List <string> {
         me
     }).ToList();
     using (var context = new ProfileContext()) {
         var profiles = from p in context.Profiles
                        where usernames.Contains(p.Username) select p;
         if (profiles.Count() != usernames.Count)
         {
             throw new Exception("Incorrect username list");
         }
         var profileIds  = from p in profiles select p.ID;
         var newDialogue = new Dialogue {
             ID      = Guid.NewGuid(),
             Members = profileIds.Select((x) => new Member {
                 MemberID = x
             }).ToList()
         };
         using (var mContext = GetContextByGuid(newDialogue.ID)) {
             mContext.Dialogues.Add(newDialogue);
             mContext.SaveChanges();
             return(newDialogue);
         }
     }
 }
예제 #2
0
 public List <string> GetAllUsernames()
 {
     using (var context = new ProfileContext()) {
         return((from p in context.Profiles
                 select p.Username).ToList());
     }
 }
예제 #3
0
 public Profile FindProfile(string username, string password)
 {
     using (var context = new ProfileContext()) {
         var profile = from p in context.Profiles
                       where p.Username == username && p.Password == password
                       select p;
         if (profile.Count() == 1)
         {
             return(profile.First());
         }
         return(null);
     }
 }
예제 #4
0
 public Profile CreateProfile(string username, string password)
 {
     using (var context = new ProfileContext()) {
         var newProfile = new Profile {
             Username = username,
             Password = password,
             ID       = Guid.NewGuid()
         };
         context.Profiles.Add(newProfile);
         context.SaveChanges();
         return(newProfile);
     }
 }
예제 #5
0
 private Profile GetProfileById(Guid Id)
 {
     if (CacheProfiles.ContainsKey(Id))
     {
         return(CacheProfiles[Id]);
     }
     using (var context = new ProfileContext()) {
         var profile = from p in context.Profiles
                       where p.ID == Id
                       select p;
         if (profile.Count() == 1)
         {
             CacheProfiles[Id] = profile.First();
             return(profile.First());
         }
         return(null);
     }
 }
예제 #6
0
 public List <Profile> GetAllProfiles()
 {
     using (var context = new ProfileContext()) {
         return(context.Profiles.ToList());
     }
 }