Esempio n. 1
0
        public void AddNewReceipt(OrderForListDto order, IEnumerable <ProductForReceiptCreation> receiptProducts)
        {
            // Add new receipt
            var total = 0;

            foreach (var item in receiptProducts)
            {
                total += item.PriceIn;
            }

            var receipt = new Receipt
            {
                OrderId      = order.Id,
                CreationTime = DateTime.Now.Date,
                UserId       = Session.CurrentUser.Id,
                Total        = total
            };

            var storedReceipt = _receipRepository.Create(receipt);

            // Add Receipt product and update product's information (priceIn, priceOut, Number)
            foreach (var item in receiptProducts)
            {
                // 1. Add Receipt product
                var receiptProduct = Mapper.Map <ReceiptProduct>(item);
                receiptProduct.ReceiptId = storedReceipt.Id;
                _receiptProductRepository.Create(receiptProduct);

                // 2. Update product's information (priceIn, priceOut, Number)
                _productRepository.UpdateSaleProperty(item.Id, item.Number, item.PriceIn);
            }

            // Update corresponding order status to done
            _orderRepository.UpdateOrderStatusById(order.Id, OrderStatus.Done);
        }
Esempio n. 2
0
        public void Create_Success_ReturnEntity()
        {
            // Arrange
            var repository = new ReceiptProductRepository();
            var input      = GenerateInput();

            // Act
            var result = repository.Create(input);

            // Assert
            Assert.That(CompareProperties(input, result));
        }
Esempio n. 3
0
        public void Get_Success_ReturnEntity()
        {
            // Arrange
            var repository = new ReceiptProductRepository();
            var input      = repository.Create(GenerateInput());

            // Act
            var result = repository.Get(input.Id);

            // Assert
            Assert.IsInstanceOf <ReceiptProduct>(result);
        }
Esempio n. 4
0
        public void GetAllByReceiptId_Success_ReturnEntities()
        {
            // Arrange
            var repository = new ReceiptProductRepository();
            var input      = repository.Create(GenerateInput());

            // Act
            var result = repository.GetAllByReceiptId(1);

            // Assert
            Assert.IsInstanceOf <IEnumerable <ReceiptProduct> >(result);
        }
Esempio n. 5
0
        public void Delete_Success_ReturnNull()
        {
            // Arrange
            var repository = new ReceiptProductRepository();
            var input      = repository.Create(GenerateInput());

            // Act
            repository.Delete(input.Id);
            var result = repository.Get(input.Id);

            // Assert
            Assert.IsNull(result);
        }
Esempio n. 6
0
        public void Update_Success_ReturnTrue()
        {
            // Arrange
            var repository = new ReceiptProductRepository();
            var input      = repository.Create(GenerateInput());

            var inputForUpdate = GenerateInput(id: input.Id);

            // Act
            var result = repository.Update(inputForUpdate);

            // Assert
            Assert.IsTrue(result);
        }