コード例 #1
0
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 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
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 public List <string> GetAllUsernames()
 {
     using (var context = new ProfileContext()) {
         return((from p in context.Profiles
                 select p.Username).ToList());
     }
 }
コード例 #3
0
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 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
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 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
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 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
ファイル: MSGService.cs プロジェクト: greenkirill/ddb
 public List <Profile> GetAllProfiles()
 {
     using (var context = new ProfileContext()) {
         return(context.Profiles.ToList());
     }
 }