Пример #1
0
        public virtual ActionResult AddTag(int productId, string tagName)
        {
            var command = new AddTagToProductCommand
            {
                ProductId = productId,
                TagName   = tagName,
                UserId    = CurrentUserId()
            };

            var result = mediator.Send(command);

            return(RedirectToAction("View", new { productId = productId }));
        }
Пример #2
0
        public void WhenBartTagsWith(string userName, string productName, string tagName)
        {
            using (var session = sessionFactory.OpenSession())
            {
                var user    = session.Query <User>().First(u => u.UserName == userName);
                var product = session.Query <UserProduct>().First(p => p.Name == productName);

                var tagUserProductCommand = new AddTagToProductCommand()
                {
                    ProductId = product.Id,
                    UserId    = user.Id,
                    TagName   = tagName
                };

                var result = new AddTagToProductCommandHandler(session).Handle(tagUserProductCommand);
            }
        }
Пример #3
0
        public void GivenUserHasSavedTheFollowingProducts(string userName, Table table)
        {
            using (var session = sessionFactory.OpenSession())
            {
                var user = session.Query <User>().First(u => u.UserName == userName);

                foreach (var row in table.Rows)
                {
                    var command = new AddProductCommand
                    {
                        UserId       = user.Id,
                        ProductName  = row["Name"],
                        ProductNotes = row["Notes"]
                    };

                    var handler  = new AddProductCommandHandler(session);
                    var response = handler.Handle(command);

                    if (row.ContainsKey("Tags") && !string.IsNullOrWhiteSpace(row["Tags"]))
                    {
                        var addTagHandler = new AddTagToProductCommandHandler(session);
                        var tagNames      = row["Tags"].Split(',').Select(t => t.Trim());
                        foreach (var tagName in tagNames)
                        {
                            var addTagCommand = new AddTagToProductCommand
                            {
                                UserId    = user.Id,
                                ProductId = response.NewProductId,
                                TagName   = tagName
                            };
                            addTagHandler.Handle(addTagCommand);
                        }
                    }
                }
            }
        }