public UserMessagesContract GetList(int id, PagingProperties paging, bool unread, IUserIconFactory iconFactory) { PermissionContext.VerifyResourceAccess(new[] { id }); return(HandleQuery(ctx => { var received = GetReceivedMessages(ctx, id, paging, unread, iconFactory); var sent = (!unread ? GetSentMessages(ctx, id, paging, iconFactory) : new UserMessageContract[0]); return new UserMessagesContract { ReceivedMessages = received, SentMessages = sent }; })); }
public PartialFindResult <UserMessageContract> GetList(int id, PagingProperties paging, UserInboxType inboxType, bool unread, IUserIconFactory iconFactory) { PermissionContext.VerifyResourceAccess(new[] { id }); return(HandleQuery(ctx => { var query = ctx.Query() .Where(u => u.User.Id == id) .WhereInboxIs(inboxType, unread) .WhereIsUnread(unread); var messages = query .OrderByDescending(m => m.Created) .Paged(paging, true) .ToArray() .Select(m => new UserMessageContract(m, iconFactory)) .ToArray(); var count = paging.GetTotalCount ? query.Count() : 0; return new PartialFindResult <UserMessageContract>(messages, count); })); }
/// <summary> /// Updates user's settings (from my settings page). /// </summary> /// <param name="contract">New properties. Cannot be null.</param> /// <returns>Updated user data. Cannot be null.</returns> /// <exception cref="InvalidEmailFormatException">If the email format was invalid.</exception> /// <exception cref="InvalidPasswordException">If password change was attempted and the old password was incorrect.</exception> /// <exception cref="UserEmailAlreadyExistsException">If the email address was already taken by another user.</exception> public UserWithPermissionsContract UpdateUserSettings(UpdateUserSettingsContract contract) { ParamIs.NotNull(() => contract); PermissionContext.VerifyPermission(PermissionToken.EditProfile); return(repository.HandleTransaction(ctx => { var user = ctx.Load(contract.Id); ctx.AuditLogger.SysLog(string.Format("Updating settings for {0}", user)); PermissionContext.VerifyResourceAccess(user); if (!string.IsNullOrEmpty(contract.NewPass)) { var oldHashed = (!string.IsNullOrEmpty(user.Password) ? LoginManager.GetHashedPass(user.NameLC, contract.OldPass, user.Salt) : string.Empty); if (user.Password != oldHashed) { throw new InvalidPasswordException(); } var newHashed = LoginManager.GetHashedPass(user.NameLC, contract.NewPass, user.Salt); user.Password = newHashed; } var email = contract.Email; if (!string.IsNullOrEmpty(email)) { ValidateEmail(email); var existing = ctx.Query().FirstOrDefault(u => u.Active && u.Id != user.Id && u.Email == email); if (existing != null) { throw new UserEmailAlreadyExistsException(); } } user.Options.AboutMe = contract.AboutMe; user.AnonymousActivity = contract.AnonymousActivity; user.Culture = contract.Culture; user.DefaultLanguageSelection = contract.DefaultLanguageSelection; user.EmailOptions = contract.EmailOptions; user.Language = contract.Language; user.Options.Location = contract.Location; user.PreferredVideoService = contract.PreferredVideoService; user.Options.PublicAlbumCollection = contract.PublicAlbumCollection; user.Options.PublicRatings = contract.PublicRatings; user.SetEmail(email); var validWebLinks = contract.WebLinks.Where(w => !string.IsNullOrEmpty(w.Url)); var webLinkDiff = WebLink.Sync(user.WebLinks, validWebLinks, user); ctx.OfType <UserWebLink>().Sync(webLinkDiff); ctx.Update(user); ctx.AuditLogger.AuditLog(string.Format("updated settings for {0}", EntryLinkFactory.CreateEntryLink(user))); return new UserWithPermissionsContract(user, PermissionContext.LanguagePreference); })); }