/// <summary> /// Accept a friendship request sent to an user by another one. /// </summary> /// <param name="sender">The user that sends the request.</param> /// <param name="reciver">The user that receives the request and optionaly accept it.</param> public void AcceptRequest(User sender, User reciver) { ContractUtil.NotNull(sender); ContractUtil.NotNull(reciver); var requestRepository = _unitOfWork.FriendshipRequests; var request = requestRepository.FindSentFrom(sender).FirstOrDefault(friendshipRequest => reciver.Id.Equals(friendshipRequest.Reciver.Id)); // Checking that the request is already sent. if (Equals(request, null)) { throw new InvalidOperationException(); } var notificationRepository = _unitOfWork.Notifications; var userRepository = _unitOfWork.Users; var senderInContext = userRepository.FindById(sender.Id); // NOTE: Rethink and Analize that var reciverInContext = userRepository.FindById(reciver.Id); var newNotification = _notificationFactory.CreateFriendshipAccepted(sender, reciver); senderInContext.AddFriend(reciverInContext); reciverInContext.AddFriend(senderInContext); notificationRepository.Add(newNotification); request.State = FriendshipRequestState.Accepted; _unitOfWork.Commit(); }
/// <summary> /// Change the current password for a given credentials. /// </summary> /// <param name="email">The email as user identifier.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> /// <returns>True if the password is successfully changed, False in other case.</returns> public bool ChangePassword(string email, string oldPassword, string newPassword) { ContractUtil.NotNull(email); ContractUtil.NotNull(oldPassword); ContractUtil.NotNull(newPassword); using (var unitOfWork = Container.Instance.Resolve <IUnitOfWork>()) { var user = unitOfWork.Users.FindByEmail(email); if (Equals(user, null)) { return(false); } if (!Equals(user.Password, EncryptPassword(oldPassword))) { return(false); } user.Password = EncryptPassword(newPassword); unitOfWork.Commit(); } return(true); }
/// <summary> /// Find friends to a given user. /// </summary> /// <param name="user">An user.</param> /// <returns>possibles friends for <paramref name="user"/></returns> public IEnumerable <User> GetPossiblesFriends(User user) { ContractUtil.NotNull(user); var users = _unitOfWork.Users; var friendshipRequests = _unitOfWork.FriendshipRequests; var filter = new Func <User, bool>(x => // no already friends !user.Friends.Contains(x) // no the same user && !user.Equals(x) // no already requested users && !friendshipRequests.FindSentTo(x).Any(request => request.Sender.Id.Equals(user.Id)) // no user that already sent a request && !friendshipRequests.FindSentFrom(x).Any(request => request.Reciver.Id.Equals(user.Id))); return(user.Friends .SelectMany(other => other.Friends) .Where(filter) .ToOccurrenceTable() .OrderByDescending(pair => pair.Value) .Select(pair => pair.Key) .Concat(users.All().Where(filter)) .Distinct()); }
/// <summary> /// Register a new user with the given credentials. /// </summary> /// <param name="firstName">The first name of the user.</param> /// <param name="lastName">The last name of the user.</param> /// <param name="email">The email of the user.</param> /// <param name="password">The password of the user.</param> /// <param name="securityQuestion">The security question of the user.</param> /// <param name="securityAnswer">The security answer of the user.</param> /// <returns>True if the new user is successfully registred, False in other case.</returns> public bool Register(string firstName, string lastName, string email, string password, string securityQuestion, string securityAnswer) { ContractUtil.NotNull(firstName); ContractUtil.NotNull(lastName); ContractUtil.NotNull(email); ContractUtil.NotNull(password); ContractUtil.NotNull(securityQuestion); ContractUtil.NotNull(securityAnswer); using (var unitOfWork = Container.Instance.Resolve <IUnitOfWork>()) { if (!Equals(unitOfWork.Users.FindByEmail(email), null)) { return(false); } var newUser = new User(firstName, lastName, email, EncryptPassword(password), securityQuestion, securityAnswer); unitOfWork.Users.Add(newUser); unitOfWork.Commit(); } return(true); }
public string CreateKey(User user) { ContractUtil.NotNull(user); var @base = GenerateBase(user); string result; var entriesRepository = _unitOfWork.Entries; var key = entriesRepository.Find(@base); if (Equals(key, null)) { entriesRepository.Add(@base); result = @base; } else { key.Count++; result = @base + key.Count; } _unitOfWork.Commit(); return(result); }
public void Add(string key) { ContractUtil.NotNull(key); var newKey = new FacebookKey(key); Set.Add(newKey); }
/// <summary> /// Adds a request to the current repository. /// </summary> /// <param name="request">A new request.</param> public void Add(FriendshipRequest request) { ContractUtil.NotNull(request); ContractUtil.IsDefault(request.Id); Set.Add(request); }
public void Add(string key) { ContractUtil.NotNull(key); var fk = new FacebookKey(key); var id = GetNewKey(); fk.Id = id; _data.Add(id, fk); }
/// <summary> /// Adds a request to the current repository. /// </summary> /// <param name="request">A new request.</param> public void Add(FriendshipRequest request) { ContractUtil.NotNull(request); ContractUtil.IsDefault(request.Id); var key = GetNewKey(); request.Id = key; _data.Add(key, request); }
/// <summary> /// Adds a post to the current repository. /// </summary> /// <param name="post">The post to add.</param> public void Add(Post post) { ContractUtil.NotNull(post); ContractUtil.IsDefault(post.Id); var key = GetNewKey(); post.Id = key; _data.Add(key, post); }
/// <summary> /// Adds a given notification to the current repository. /// </summary> /// <param name="notification">The notification to add.</param> public void Add(Notification notification) { ContractUtil.NotNull(notification); ContractUtil.IsDefault(notification.Id); var id = GetNewKey(); notification.Id = id; _data.Add(id, notification); }
/// <summary> /// Adds a new user to the current repository. /// </summary> /// <param name="user">The new user to add.</param> public void Add(User user) { ContractUtil.NotNull(user); var key = Container.Instance.Resolve <IKeyGenerationService>().CreateKey(user); // TODO: Maybe inject dependency through the constructor user.Keyword = key; Set.Add(user); }
/// <summary> /// Adds a message to the current repository. /// </summary> /// <param name="message">The message to add.</param> public void Add(Message message) { ContractUtil.NotNull(message); ContractUtil.IsDefault(message.Id); var key = GetNewKey(); message.Id = key; _data.Add(key, message); }
public AccountController(IMembershipProvider membershipProvider, IUserProvider userProvider, IWebSecurity webSecurity) { ContractUtil.NotNull(membershipProvider); ContractUtil.NotNull(userProvider); ContractUtil.NotNull(webSecurity); _userProvider = userProvider; _membershipProvider = membershipProvider; _webSecurity = webSecurity; }
/// <summary> /// Retrieve the owner posts that will be show to a given user. /// </summary> /// <param name="user">An user.</param> /// <param name="page">The page number.</param> /// <param name="count">The posts count.</param> /// <returns></returns> public IList <Post> GetOwnerPosts(User user, int page = 1, int count = 10) { ContractUtil.NotNull(user); var postRepository = _unitOfWork.Posts; return(postRepository.FindPostsTo(user) .OrderByDescending(post => post.Date) .Paginate(page, count) .ToList()); }
/// <summary> /// Validate a given user credentials. /// </summary> /// <param name="email">The email to validate.</param> /// <param name="password">The associated password to validate.</param> /// <returns>True if the credentials are validated, False in other case.</returns> public bool Validate(string email, string password) { ContractUtil.NotNull(email); ContractUtil.NotNull(password); using (var unitOfWork = Container.Instance.Resolve <IUnitOfWork>()) { var user = unitOfWork.Users.FindByEmail(email); return(!Equals(user, null) && Equals(user.Password, EncryptPassword(password))); } }
public IEnumerable <Notification> GetNotifications(User user) { ContractUtil.NotNull(user); foreach (var notification in _unitOfWork.Notifications.FindNotificationsFor(user) .Where(notification => !notification.IsRead)) { notification.IsRead = true; //_unitOfWork.Commit(); yield return(notification); } }
/// <summary> /// Adds a new user to the current repository. /// </summary> /// <param name="user">The new user to add.</param> public void Add(User user) { ContractUtil.NotNull(user); ContractUtil.IsDefault(user.Id); var keyword = Container.Instance.Resolve <IKeyGenerationService>().CreateKey(user); // TODO: Maybe inject dependency through the constructor user.Keyword = keyword; var key = GetNewKey(); user.Id = key; _data.Add(key, user); }
/// <summary> /// Retrieve the posts that will be show to a given user. /// </summary> /// <param name="user">An user.</param> /// <param name="page">The page number.</param> /// <param name="count">The posts count.</param> /// <returns></returns> public IList <Post> GetPosts(User user, int page = 1, int count = 10) { ContractUtil.NotNull(user); ContractUtil.IsInRange(page, 1); ContractUtil.IsInRange(count, 1); var postRepository = _unitOfWork.Posts; return(user.Friends.SelectMany(postRepository.FindPostsTo) .Where(post => post.IsPersonal) .Concat(postRepository.FindPostsTo(user)) .OrderByDescending(post => post.Date) .Paginate(page, count) .ToList()); }
/// <summary> /// Send a friendship request from an user to another one. /// </summary> /// <param name="sender">The user that sends the request.</param> /// <param name="reciver">The user that receives the request.</param> public void SendRequest(User sender, User reciver) { ContractUtil.NotNull(sender); ContractUtil.NotNull(reciver); var requestRepository = _unitOfWork.FriendshipRequests; // Checking that the request isn't already sent ... if (requestRepository.FindSentFrom(sender).Any(request => reciver.Id.Equals(request.Reciver.Id))) { return; } var notificationRepository = _unitOfWork.Notifications; var newRequest = new FriendshipRequest(sender, reciver, _dateTimeService.Now()); var newNotification = _notificationFactory.CreateFriendshipRequest(sender, reciver); requestRepository.Add(newRequest); notificationRepository.Add(newNotification); _unitOfWork.Commit(); }
public FriendshipStatus GetFriendshipStatus(User current, User other) { ContractUtil.NotNull(current); ContractUtil.NotNull(other); if (current.Equals(other)) { throw new Exception(); } if (current.Friends.Contains(other)) { return(FriendshipStatus.AlreadyFriends); } if (_unitOfWork.FriendshipRequests.FindSentTo(other).Any(request => request.Sender.Id.Equals(current.Id))) { return(FriendshipStatus.RequestSentByYou); } if (_unitOfWork.FriendshipRequests.FindSentFrom(other).Any(request => request.Reciver.Id.Equals(current.Id))) { return(FriendshipStatus.RequestSentByOther); } return(FriendshipStatus.NoRelation); }
/// <summary> /// Retrieve the posts that were posted by a given account: <paramref name="author"/> /// </summary> /// <param name="author">An account.</param> /// <returns>The posts that were posted by <paramref name="author"/></returns> public IQueryable <Post> FindPostsFrom(User author) { ContractUtil.NotNull(author); return(Set.Where(post => post.Author.Id.Equals(author.Id))); }
/// <summary> /// Retrieve all requests that are sent to a given user. /// </summary> /// <param name="user">Reciver</param> /// <param name="spec">An optional aditional specification. </param> /// <returns>All the friendship request that <paramref name="user"/> had receive.</returns> public IQueryable <FriendshipRequest> FindSentTo(User user) { ContractUtil.NotNull(user); return(Set.Where(request => request.Reciver.Id.Equals(user.Id))); }
public User FindByKeyword(string keyword) { ContractUtil.NotNull(keyword); return(Set.SingleOrDefault(account => keyword.Equals(account.Keyword))); }
public IEnumerable <Message> GetMessages(User user) { ContractUtil.NotNull(user); return(_unitOfWork.Messages.FindMessagesTo(user).OrderByDescending(message => message.Date)); }
public void Add(Image img) { ContractUtil.NotNull(img); Set.Add(img); }
public void Update(Business.Domain.Users.User user) { ContractUtil.NotNull(user); if (Image != null) { var format = Path.GetExtension(Image.FileName); var data = new byte[Image.InputStream.Length]; Image.InputStream.Read(data, 0, data.Length); var img = new Image(data, format, ""); user.SetPhoto(img); } if (State != user.Profile.ContactInformation.Address.State) { user.Profile.ContactInformation.Address.State = State; } if (AboutMe != user.Profile.PersonalInformation.AboutMe) { user.Profile.PersonalInformation.AboutMe = AboutMe; } if (City != user.Profile.ContactInformation.Address.City) { user.Profile.ContactInformation.Address.City = City; } if (BirthDay != user.Profile.PersonalInformation.BirthDay) { user.Profile.PersonalInformation.BirthDay = BirthDay; } if (HomeTown != user.Profile.PersonalInformation.HomeTown) { user.Profile.PersonalInformation.HomeTown = HomeTown; } if (EMail != user.Profile.ContactInformation.EMail) { user.Profile.ContactInformation.EMail = EMail; } if (EMailOnlyForFriends != user.Profile.ContactInformation.EMailOnlyForFriends) { user.Profile.ContactInformation.EMailOnlyForFriends = EMailOnlyForFriends; } if (Country != user.Profile.ContactInformation.Address.Country) { user.Profile.ContactInformation.Address.Country = Country; } if (AddressInfo != user.Profile.ContactInformation.Address.AddressInfo) { user.Profile.ContactInformation.Address.AddressInfo = AddressInfo; } if (AddressOnlyForFriends != user.Profile.ContactInformation.AddressOnlyForFriends) { user.Profile.ContactInformation.AddressOnlyForFriends = AddressOnlyForFriends; } if (InterestedInMen != user.Profile.PersonalInformation.InterestedInMen) { user.Profile.PersonalInformation.InterestedInMen = InterestedInMen; } if (InterestedInWomen != user.Profile.PersonalInformation.InterestedInWomen) { user.Profile.PersonalInformation.InterestedInWomen = InterestedInWomen; } if (LookingForFriendship != user.Profile.PersonalInformation.LookingForFriendship) { user.Profile.PersonalInformation.LookingForFriendship = LookingForFriendship; } if (LookingForRelationship != user.Profile.PersonalInformation.LookingForRelationship) { user.Profile.PersonalInformation.LookingForRelationship = LookingForRelationship; } if (MobileNumber != user.Profile.ContactInformation.MobileNumber) { user.Profile.ContactInformation.MobileNumber = MobileNumber; } if (MobileNumberOnlyForFriends != user.Profile.ContactInformation.MobileNumberOnlyForFriends) { user.Profile.ContactInformation.MobileNumberOnlyForFriends = MobileNumberOnlyForFriends; } }
/// <summary> /// Retrieve the user with the given email. /// </summary> /// <param name="email">The email of the user.</param> /// <returns></returns> public User FindByEmail(string email) { ContractUtil.NotNull(email); return(Set.SingleOrDefault(account => email.Equals(account.EMail))); }
/// <summary> /// Retrieve the posts that were posted to a given account: <paramref name="owner"/> /// </summary> /// <param name="owner">An account.</param> /// <returns>The posts that were poetd to <paramref name="owner"/></returns> public IQueryable <Post> FindPostsTo(User owner) { ContractUtil.NotNull(owner); return(Set.Where(post => post.Owner.Id.Equals(owner.Id))); }
/// <summary> /// Adds a post to the current repository. /// </summary> /// <param name="post">The post to add.</param> public void Add(Post post) { ContractUtil.NotNull(post); Set.Add(post); }