public async Task <IActionResult> Settings() { var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name); var profile = await _profileManager.GetProfileAsync(userId); var tagIds = (await _tagManager.GetUserTagsAsync(userId)).Select(tag => tag.Id); var allTags = (await _tagManager.GetAllTagsAsync()).ToList(); var tagViewModels = new List <TagViewModel>(); if (allTags.Any()) { foreach (var tag in allTags) { tagViewModels.Add(new TagViewModel() { Id = tag.Id, Name = tag.Name }); } } var settingsViewModel = new SettingsViewModel() { Id = profile.Id, Name = profile.Name, Info = profile.Info, IsVendor = profile.IsVendor, UserId = profile.UserId, TagIds = tagIds.ToArray(), AllTags = tagViewModels, Avatar = profile.Avatar }; return(View(settingsViewModel)); }
public async Task <IActionResult> Index(string userName) { userName = userName ?? User.Identity.Name; var userId = await _accountManager.GetUserIdByNameAsync(userName); var profile = await _profileManager.GetProfileAsync(userId); var comments = await _orderManager.GetUserCommentsAsync(userId); var tags = await _tagManager.GetUserTagsAsync(userId); var commentViewModels = new List <CommentViewModel>(); var tagViewModels = new List <TagViewModel>(); double?rating = null; if (comments.Any()) { foreach (var comment in comments) { var author = await _profileManager.GetProfileAsync(comment.AuthorId); commentViewModels.Add(new CommentViewModel { OrderId = comment.OrderId, Created = comment.Created, Rating = comment.Rating, Text = comment.Text, AuthorName = author.Name, AuthorAvatar = author.Avatar, AuthorUserName = await _accountManager.GetUserNameByIdAsync(author.UserId) }); } rating = commentViewModels.Select(comment => comment.Rating).Average(); } if (tags.Any()) { foreach (var tag in tags) { tagViewModels.Add(new TagViewModel { Id = tag.Id, Name = tag.Name }); } } var ordersCompleted = (await _orderManager.GetIncomingOrdersAsync(profile.UserId)) .Where(order => order.State == StateType.Completed).Count(); var profileViewModel = new ProfileViewModel() { Id = profile.Id, UserId = profile.UserId, UserName = userName, Avatar = profile.Avatar, Created = profile.Created, IsVendor = profile.IsVendor, Info = profile.Info, Name = profile.Name, Rating = rating, Comments = commentViewModels, Tags = tagViewModels, OrdersCompleted = ordersCompleted }; return(View(profileViewModel)); }
public async Task <IActionResult> Profile(string searchString, IList <int> tagIds) { var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name); var profileViewModels = new List <ProfileViewModel>(); var profiles = (await _profileManager.GetProfilesByTagsAsync(tagIds)).Where(profile => profile.UserId != userId).ToList(); if (!String.IsNullOrEmpty(searchString)) { profiles = profiles.Where(profile => profile.Name.Contains(searchString)).ToList(); } if (profiles.Any()) { foreach (var profile in profiles) { var tags = await _tagManager.GetUserTagsAsync(profile.UserId); var tagViewModels = new List <TagViewModel>(); if (tags.Any()) { foreach (var tag in tags) { tagViewModels.Add(new TagViewModel { Id = tag.Id, Name = tag.Name }); } } double?rating = null; var comments = await _orderManager.GetUserCommentsAsync(profile.UserId); if (comments.Any()) { rating = comments.Select(comment => comment.Rating).Average(); } var ordersCompleted = (await _orderManager.GetIncomingOrdersAsync(profile.UserId)) .Where(order => order.State == StateType.Completed).Count(); profileViewModels.Add(new ProfileViewModel() { Id = profile.Id, Name = profile.Name, Avatar = profile.Avatar, Created = profile.Created, Info = profile.Info, UserName = await _accountManager.GetUserNameByIdAsync(profile.UserId), IsVendor = profile.IsVendor, UserId = profile.UserId, Rating = rating, Tags = tagViewModels, OrdersCompleted = ordersCompleted }); } } var allTagsViewModels = new List <TagViewModel>(); var allTags = await _tagManager.GetAllTagsAsync(); if (allTags.Any()) { foreach (var tag in allTags) { allTagsViewModels.Add(new TagViewModel() { Id = tag.Id, Name = tag.Name }); } } return(View(( allTagsViewModels, profileViewModels))); }