public class Chat { [Key] public int MessageId { get; set; } [Required] public int FromUserId { get; set; } [Required] public int ToUserId { get; set; } [Required] public string Message { get; set; } [Required] public DateTime Time { get; set; } public virtual ICollection<UserProfile> UserProfiles { get; set; } }
var name = db.UserProfiles.Find(2);
public void getMessages() { var db = new UsersContext(); var messages = from a in db.Messages where a.FromUserId== WebSecurity.CurrentUserId || a.ToUserId==WebSecurity.CurrentUserId select a; foreach(var a in messages) { if (a.FromUserId == WebSecurity.CurrentUserId) { Clients.Caller.addNewMessageToPage(WebSecurity.CurrentUserName, a.Message); } else { var name = db.UserProfiles.Find(2); Clients.Caller.addNewMessageToPage(name.UserName, a.Message); } } db.Dispose(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)