public override CommandResponse <Nop> Handle(UpdateCartViewModelCommand task)
        {
            var cart = _repository.GetAllAndInclude(new List <Expression <Func <Cart, object> > >
            {
                x => x.Items,
                x => x.Coupons
            })
                       .OrderByDescending(x => x.Created)
                       .FirstOrDefault(x => x.UserId == task.UserId);

            var items     = GetItems(cart);
            var viewModel = new CartViewModel
            {
                Id            = task.UserId,
                RootEntityKey = task.UserId,
                Items         = items,
                SubTotal      = items.Sum(x => x.Price)
            };

            _viewModelRepository.Save(viewModel);

            Mediator.InternalEvent(new CartViewModelUpdatedEvent {
                UserId = task.UserId
            });

            return(CommandResponse.Succeeded(Nop.NoValue));
        }
Beispiel #2
0
        public override CommandResponse <Nop> Handle(UpdateHomePageViewModelCommand task)
        {
            var products = _repository.GetAll <Product>().ToArray();

            var homepageModel = new HomePageViewModelBuilder().SetInputs(new Dictionary <string, object>
            {
                { HomePageViewModelBuilder.Keys.Products, products }
            }).Build();

            _viewModelRepository.Save(homepageModel);

            Mediator.Notification(new HomePageUpdatedUiEvent());
            return(CommandResponse.Succeeded(Nop.NoValue));
        }
Beispiel #3
0
        public override CommandResponse <Nop> Handle(CreateNewSessionViewModelCommand task)
        {
            _repository.Save(new SessionViewModel
            {
                Id            = task.SessionId,
                Name          = "",
                RootEntityKey = task.SessionId
            });

            Mediator.InternalEvent(new SessionViewModelCreatedEvent {
                SessionId = task.SessionId
            });


            return(CommandResponse.Succeeded(Nop.NoValue));
        }