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); } } }
public List <string> GetAllUsernames() { using (var context = new ProfileContext()) { return((from p in context.Profiles select p.Username).ToList()); } }
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); } }
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); } }
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); } }
public List <Profile> GetAllProfiles() { using (var context = new ProfileContext()) { return(context.Profiles.ToList()); } }