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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新建商品界面
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> Create()
        {
            var brands = await brandManager.GetAllBrandsAsync();

            var tags = await tagManager.GetAllTagsAsync();

            var specifications = await specificationManager.GetAllSpecificationsAsync();

            CreateProductModel model = new CreateProductModel
            {
                Brands         = brands,
                Tags           = tags,
                Specifications = specifications
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        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)));
        }