Esempio n. 1
0
        public void MakeOrder(Order order)
        {
            UnitOfWork.GetRepository<Order>().Insert(order);
            var price = order.ContentPackage.Price;

            var profileService = new ProfileService(UnitOfWork);
            var ownerProfile = profileService.GetUserProfile(order.ContentPackage.Owner);

            order.UserProfile.Balance -= price;
            ownerProfile.Balance += price;

            UnitOfWork.Save();
        }
        public ViewResult MakeOrder(OrderViewModel viewModel)
        {
            var packageId = viewModel.ContentPackageId;
            var package = UnitOfWork.GetRepository<ContentPackage>().GetByID(packageId);

            var order = new Order
                        {
                            ContentPackage = package,
                            UserProfile = CurrentUserProfile
                        };

            var financeService = new FinanceService(UnitOfWork);
            financeService.MakeOrder(order);

            return InformationView("Покупка успешно произведена.",
                                   "",
                                   new ActionLinkInfo("Content",
                                                      "Details",
                                                      "Вернуться к просмотру",
                                                      new {id = package.ID}));
        }
        public void UserHasPermissions_UserOrderedPackage_UserHasPermissions()
        {
            // Arrange
            var unitOfWork = new UnitOfWorkMock();
            var user = new User();
            var userProfile = new UserProfile {User = user};
            var package = new ContentPackage {Owner = new User()};
            unitOfWork.GetRepository<User>().Insert(user);
            unitOfWork.GetRepository<UserProfile>().Insert(userProfile);
            unitOfWork.GetRepository<ContentPackage>().Insert(package);

            var order = new Order {ContentPackage = package, UserProfile = userProfile};
            unitOfWork.GetRepository<Order>().Insert(order);
            unitOfWork.Save();

            // Act
            var financeService = new FinanceService(unitOfWork);
            var userHasPermissions = financeService.UserHasPermissions(user, package);

            // Assert
            userHasPermissions.Should().BeTrue();
        }
        public ViewResult Order(int id)
        {
            var package = UnitOfWork.GetRepository<ContentPackage>().GetByID(id);
            if (package == null)
                return ErrorView("Материал не найден", "Указанный материал отсутствует в базе данных.");

            var viewModel = new OrderViewModel
                            {
                                OrderPrice = package.Price,
                                UserBalance = CurrentUserProfile.Balance,
                                ContentPackageId = package.ID
                            };

            var financeService = new FinanceService(UnitOfWork);
            var order = new Order
                        {
                            ContentPackage = package,
                            UserProfile = CurrentUserProfile,
                        };
            if (!financeService.IsOrderAvailable(order))
                ModelState.AddModelError("balance", "Недостаточно средств для покупки текущего материала.");

            return View(viewModel);
        }
Esempio n. 5
0
 public bool IsOrderAvailable(Order order)
 {
     return order.ContentPackage.Price <= order.UserProfile.Balance;
 }