/** * Purpose: Provide a BaseViewModel for all views to prevent copying code, by setting properties * common to all views on creation of each new view model. All view models inherit from * the BaseViewModel. * Arguments: * FriendBookContext ctx - Gives access and connection to the database * Return: * None */ public BaseViewModel(FriendBookContext context) { int UserId = ActiveUser.Instance.User.UserId; //GETS ALL OF THE CURRENT USERS PENDING FRIEND REQUEST SENT TO HIM/HER var FRsSentToUser = context.Relationship.Where(r => r.ReciverUserId == UserId && r.Status == 0).ToList(); foreach (Relationship r in FRsSentToUser) { r.SenderUser = context.User.Where(u => u.UserId == r.SenderUserId).SingleOrDefault(); r.ReceivingUser = context.User.Where(u => u.UserId == r.ReciverUserId).SingleOrDefault(); } FriendRequests = FRsSentToUser; //SETS THE STYLE OF THE CURRENT LOGGED IN USER CurrentUserStyle = context.Style.Where(s => s.UserId == UserId).SingleOrDefault(); //SETS THE CURRENTUSER PROPERTY EQUAL TO THE CURRENT LOGGED IN USER CurrentUser = context.User.Where(u => u.UserId == UserId).SingleOrDefault(); //GETS ALL OF THE CURRENT USERS FRIENDS AND SETS THAT LIST EQUAL TO THE USERFRIENDS //PROPERTY IN THE BASEVIEWMODEL List <Relationship> UserRelationships = context.Relationship.Where(u => u.ReciverUserId == UserId || u.SenderUserId == UserId).ToList(); List <User> CurrentUserFriends = new List <User> { }; foreach (Relationship r in UserRelationships) { if (r.ReciverUserId == UserId && r.Status == 1) { CurrentUserFriends.Add(context.User.Where(u => u.UserId == r.SenderUserId).SingleOrDefault()); } else if (r.SenderUserId == UserId && r.Status == 1) { CurrentUserFriends.Add(context.User.Where(u => u.UserId == r.ReciverUserId).SingleOrDefault()); } } //GET ALL MESSAGE NOTIFICATIONS FOR CURRENT USER List <MessageNotification> MN = context.MessageNotification.Where(mn => mn.RecievingUserId == UserId && mn.Seen == false).ToList(); MN.ForEach(n => n.RecievingUser = context.User.Where(u => u.UserId == n.RecievingUserId).SingleOrDefault()); MessageNotifications = MN; //GET LIST OF ALL FRIENDS OF A CURRENT USER UserFriends = CurrentUserFriends.OrderBy(f => f.FirstName + f.LastName).ToList(); //GETS LIST OF ALL THE CURRENT USER'S NOTIFICATIONS List <Notification> UN = context.Notification.Where(n => n.RecievingUserId == UserId && n.Seen == false).ToList(); UN.ForEach(un => un.SendingUser = context.User.Where(u => u.UserId == un.SenderUserId).SingleOrDefault()); UN.ForEach(un => un.RecievingUser = context.User.Where(u => u.UserId == un.RecievingUserId).SingleOrDefault()); UserNotifications = UN.OrderByDescending(un => un.NotificatonDate).ToList(); }
/** * Purpose: Provide a BaseViewModel for all Profile type views to prevent copying code, by setting properties * common to all profile based views on creation of each profile based view model. Each of these profile * based view models inherit from the ProfileBaseViewModel. * Arguments: * FriendBookContext ctx - Gives access and connection to the database * int UserProfileId - the UserId of the current profile that is being visited. * Return: * None */ public ProfileBaseViewModel(FriendBookContext ctx, int UserProfileId) : base(ctx) { //WHEN A NEW INSTANCE OF PROFILEBASEVIEWMODEL IS CREATED, IT GETS THE CURRENT USER PROFILES ID AND SETS THE //USER PROFILE EQUAL TO THAT USER, GETS THE STYLE OF THAT PARTICULAR USER, QUERIES THROUGH ALL RELATIONSHIPS //TO FIND THE TYPE OF RELATIONSHIP SHARED BETWEEN THE CURRENT LOGGED IN USER, AND THE PROFILE BEING VIEWED User LoggedInUser = ActiveUser.Instance.User; //THE USER WHOSE PROFILE IS BEING VISITED User user = ctx.User.Where(u => u.UserId == UserProfileId).SingleOrDefault(); UserProfile = user; //SETS THE CURRENT USER'S STYLE OF THE PROFILE BEING VISITED Style style = ctx.Style.Where(s => s.UserId == UserProfileId).SingleOrDefault(); UserStyle = style; //DETERMINES THE RELATIONSHIP BETWEEN THE CURRENT USER AND THE USER'S PROFILE THAT IS BEING VISITED List <Relationship> relationships = ctx.Relationship.Where(r => r.ReciverUserId == UserProfileId || r.SenderUserId == UserProfileId).ToList(); this.AreFriends = "NoRelationship"; foreach (Relationship r in relationships) { if (r.SenderUserId == LoggedInUser.UserId || r.ReciverUserId == LoggedInUser.UserId) { if (r.Status == 0) { this.AreFriends = "Pending"; } else if (r.Status == 1) { this.AreFriends = "yes"; } else if (r.Status == 2) { this.AreFriends = "no"; } else if (r.Status == 3) { this.AreFriends = "blocked"; } } } }
public ProfileController(FriendBookContext ctx, IHostingEnvironment environment) { _environment = environment; context = ctx; }
public ProfileStylingViewModel(FriendBookContext ctx, int UserId) : base(ctx, UserId) { }
public HomePageViewModel(FriendBookContext ctx) : base(ctx) { }
public ConversationIndexViewModel(FriendBookContext ctx) : base(ctx) { }
public PostController(FriendBookContext ctx) { context = ctx; }
public ProfileIndexViewModel(FriendBookContext ctx, int id) : base(ctx, id) { }
public ProfileFriendsViewModel(FriendBookContext ctx, int UserProfileId) : base(ctx, UserProfileId) { }
public YardSaleNewItemViewModel(FriendBookContext ctx) : base(ctx) { }
public LoginController(FriendBookContext ctx) { context = ctx; }
public YardSaleHomeViewModel(FriendBookContext ctx) : base(ctx) { }
public ConversationMessagesViewModel(FriendBookContext ctx) : base(ctx) { }
public ConversationController(FriendBookContext ctx) { context = ctx; }