Пример #1
0
        public void Execute(CreateSaleModel model)
        {
            var date = _dateService.GetDate();

            var customer = _database.Customers
                           .Single(p => p.Id == model.CustomerId);

            var employee = _database.Employees
                           .Single(p => p.Id == model.EmployeeId);

            var product = _database.Products
                          .Single(p => p.Id == model.ProductId);

            var quantity = model.Quantity;

            var sale = _factory.Create(
                date,
                customer,
                employee,
                product,
                quantity);

            _database.Sales.Add(sale);

            _database.Save();

            _inventory.NotifySaleOcurred(product.Id, quantity);
        }
Пример #2
0
        public void Execute(CreateSaleModel model)
        {
            var date = _dateService.GetDate();

            var customer = _respositories
                           .GetCustomer(model.CustomerId);

            var employee = _respositories
                           .GetEmployee(model.EmployeeId);

            var product = _respositories
                          .GetProduct(model.ProductId);

            var quantity = model.Quantity;

            var sale = _factory.Create(
                date,
                customer,
                employee,
                product,
                quantity);

            _respositories.AddSale(sale);

            _unitOfWork.Save();

            _inventory.NotifySaleOcurred(product.Id, quantity);
        }
        public void Execute(CreateSaleModel model)
        {
            var date = _dateService.GetDate();

            var customer = _database.Customers
                .First(p => p.Id == model.CustomerId);

            var employee = _database.Employees
                .First(p => p.Id == model.EmployeeId);

            var product = _database.Products
                .First(p => p.Id == model.ProductId);

            var quantity = model.Quantity;

            var sale = _factory.Create(
                date,
                customer, 
                employee, 
                product, 
                quantity);

            _database.Sales.Add(sale);

            _database.Save();

            _client.NotifySaleOcurred(product.Id, quantity);
        }
Пример #4
0
        public void SetUp()
        {
            var customer = new Customer
            {
                Id = CustomerId
            };

            var employee = new Employee
            {
                Id = EmployeeId
            };

            var product = new Product
            {
                Id    = ProductId,
                Price = UnitPrice
            };

            _model = new CreateSaleModel()
            {
                CustomerId = CustomerId,
                EmployeeId = EmployeeId,
                ProductId  = ProductId,
                Quantity   = Quantity
            };

            _sale = new Sale();

            _mocker = new AutoMoqer();

            _mocker.GetMock <IDateService>()
            .Setup(p => p.GetDate())
            .Returns(Date);

            _mocker.GetMock <ISaleRepositoryFacade>()
            .Setup(p => p.GetCustomer(CustomerId))
            .Returns(customer);

            _mocker.GetMock <ISaleRepositoryFacade>()
            .Setup(p => p.GetEmployee(EmployeeId))
            .Returns(employee);

            _mocker.GetMock <ISaleRepositoryFacade>()
            .Setup(p => p.GetProduct(ProductId))
            .Returns(product);

            _mocker.GetMock <ISaleFactory>()
            .Setup(p => p.Create(
                       Date,
                       customer,
                       employee,
                       product,
                       Quantity))
            .Returns(_sale);

            _command = _mocker.Create <CreateSaleCommand>();
        }
Пример #5
0
        public void SetUp()
        {
            var customer = new Customer
            {
                Id = CustomerId
            };

            var employee = new Employee
            {
                Id = EmployeeId
            };

            var product = new Product
            {
                Id    = ProductId,
                Price = UnitPrice
            };

            _model = new CreateSaleModel
            {
                CustomerId = CustomerId,
                EmployeeId = EmployeeId,
                ProductId  = ProductId,
                Quantity   = Quantity
            };

            _sale = new Sale();

            _mocker = new AutoMoqer();

            _mocker.GetMock <IDateService>()
            .Setup(p => p.GetDate())
            .Returns(Date);

            SetUpDbSet(p => p.Customers, customer);
            SetUpDbSet(p => p.Employees, employee);
            SetUpDbSet(p => p.Products, product);
            SetUpDbSet(p => p.Sales);

            _mocker.GetMock <ISaleFactory>()
            .Setup(
                p => p.Create(
                    Date,
                    customer,
                    employee,
                    product,
                    Quantity))
            .Returns(_sale);

            _command = _mocker.Create <CreateSaleCommand>();
        }
        public RedirectToRouteResult Create(CreateSaleViewModel viewModel)
        {
            var model = new CreateSaleModel()
            {
                CustomerId = viewModel.Sale.CustomerId,
                EmployeeId = viewModel.Sale.EmployeeId,
                ProductId = viewModel.Sale.ProductId,
                Quantity = viewModel.Sale.Quantity
            };

            _createCommand.Execute(model);

            return RedirectToAction("index", "sales");
        }