コード例 #1
0
        public async Task Create(PurchaseCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var supplier = await _supplierRepo.GetById(dto.SupplierId).ConfigureAwait(false) ?? throw new Exception("Supplier not found!!!");


            var purchase = new Purchase(supplier, dto.Discount);

            foreach (var data in dto.PurchaseDetails)
            {
                var item = await _itemRepo.GetById(data.ItemId).ConfigureAwait(false) ?? throw new Exception("Item not found!");

                purchase.AddPurchaseDetails(item, data.Qty, data.Rate, data.SalesRate);
                item.AddQty(data.Qty);
                item.UpdateRate(data.SalesRate);
                await _itemRepo.UpdateAsync(item).ConfigureAwait(false);
            }

            await _purchaseRepo.InsertAsync(purchase).ConfigureAwait(false);



            tx.Complete();
        }
コード例 #2
0
        public async Task Create(ItemCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var item = new Item(dto.Unit, dto.ItemName, dto.Price);
            await _itemRepo.InsertAsync(item);

            tx.Complete();
        }
コード例 #3
0
        public async Task Create(UnitCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            await ValidateUnit(dto.Name);

            var Unit = new Unit(dto.Name);
            await _unitRepo.InsertAsync(Unit).ConfigureAwait(false);

            tx.Complete();
        }
コード例 #4
0
        public async Task Delete(long id)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var item = await _itemRepo.GetById(id).ConfigureAwait(false);

            await _itemRepo.DeleteAsync(item);

            tx.Complete();
        }
コード例 #5
0
        public async Task Create(SupplierCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            await ValidateSupplierNumber(dto.Phone);

            var supplier = new Supplier(dto.Name, dto.Address, dto.Email, dto.Phone);

            await _supplierRepo.InsertAsync(supplier).ConfigureAwait(false);

            tx.Complete();
        }
コード例 #6
0
        public async Task Create(CustomerTransactionCreateDto dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var customer = await _customerRepo.GetById(dto.CustomerId).ConfigureAwait(false) ?? throw new CustomerNotFoundException();

            CustomerTransaction Transaction = new CustomerTransaction(customer, dto.Amount, dto.Type, dto.ExtraId);
            await _transactionRepo.InsertAsync(Transaction).ConfigureAwait(false);

            tx.Complete();
        }
コード例 #7
0
        public async Task Update(ItemUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var item = await _itemRepo.GetById(dto.ItemId).ConfigureAwait(false) ?? throw new ItemNotFoundException();

            item.Update(dto.Unit, dto.Name, dto.Price);
            await _itemRepo.UpdateAsync(item);

            tx.Complete();
        }
コード例 #8
0
        public async Task Deactivate(long id)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var item = await _unitRepo.GetById(id).ConfigureAwait(false);

            item.Disable();

            await _unitRepo.UpdateAsync(item).ConfigureAwait(false);

            tx.Complete();
        }
コード例 #9
0
        public async Task Update(UnitUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            var Unit = await _unitRepo.GetById(dto.UnitId).ConfigureAwait(false);

            await ValidateUnit(dto.Name, Unit);

            Unit.Update(dto.Name);
            await _unitRepo.UpdateAsync(Unit);

            tx.Complete();
        }
コード例 #10
0
        public async Task Deactivate(long id)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var supplier = await _supplierRepo.GetById(id).ConfigureAwait(false) ?? throw new System.Exception("Supplier Not Found.");

            supplier.Disable();

            await _supplierRepo.UpdateAsync(supplier).ConfigureAwait(false);

            tx.Complete();
        }
コード例 #11
0
        public async Task Update(SupplierUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var supplier = await _supplierRepo.GetById(dto.Id).ConfigureAwait(false) ?? throw new System.Exception("Supplier Not Found.");

            await ValidateSupplierNumber(dto.Phone, supplier);

            supplier.Update(dto.Name, dto.Address, dto.Email, dto.Phone);

            await _supplierRepo.UpdateAsync(supplier);

            tx.Complete();
        }
コード例 #12
0
        public async Task Create(CustomerCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            await ValidateCustomerNumber(dto.PhoneNumber);

            var customer = new Customer(dto.FullName);

            customer.Email       = dto.Email;
            customer.Address     = dto.Address;
            customer.PhoneNumber = dto.PhoneNumber;
            customer.Gender      = dto.Gender;


            await _customerRepo.InsertAsync(customer);

            tx.Complete();
        }
コード例 #13
0
        public async Task Update(CustomerUpdateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();

            var customer = await _customerRepo.GetById(dto.CusId).ConfigureAwait(false);

            await ValidateCustomerNumber(dto.PhoneNumber, customer).ConfigureAwait(false);

            customer.Update(dto.FullName);
            customer.Email       = dto.Email;
            customer.PhoneNumber = dto.PhoneNumber;
            customer.Gender      = dto.Gender;
            customer.Address     = dto.Address;

            await _customerRepo.UpdateAsync(customer);

            tx.Complete();
        }
コード例 #14
0
        public async Task <Sale> Create(SaleCreateDTO dto)
        {
            using var tx = TransactionScopeHelper.GetInstance();
            var Customer = await _customerRepo.GetById(dto.CusId).ConfigureAwait(false);

            var sale = new Sale
            {
                customer     = Customer,
                total        = dto.total,
                CusId        = dto.CusId,
                netTotal     = dto.netTotal,
                discount     = dto.discount,
                SalesDate    = DateTime.Now,
                paidAmount   = dto.paidAmount,
                returnAmount = dto.returnAmount,
                dueAmount    = Math.Abs(dto.paidAmount - (dto.netTotal + dto.returnAmount))
            };


            await _saleRepo.InsertAsync(sale).ConfigureAwait(false);



            foreach (var SaleData in dto.SaleDetails)
            {
                var SaleDetail = new SaleDetails
                {
                    Qty      = SaleData.Qty,
                    Total    = SaleData.Total,
                    Price    = SaleData.Price,
                    SaleId   = sale.SaleId,
                    ItemName = SaleData.ItemName
                };
                var item = await _itemRepo.GetById(SaleData.ItemId);

                item.DecreaseQty(SaleData.Qty);
                await _itemRepo.UpdateAsync(item);

                await _saleDetailRepo.InsertAsync(SaleDetail).ConfigureAwait(false);
            }
            //Type Sales
            await _transactionService.Create(new CustomerTransactionCreateDto()
            {
                CustomerId = sale.CusId,
                Amount     = sale.netTotal,
                ExtraId    = sale.SaleId,
                Type       = CustomerTransaction.TypeSales
            }).ConfigureAwait(false);

            // Type payment
            if (sale.paidAmount - sale.returnAmount > 0)
            {
                await _transactionService.Create(new CustomerTransactionCreateDto()
                {
                    CustomerId = sale.CusId,
                    Amount     = sale.paidAmount - sale.returnAmount,
                    ExtraId    = sale.SaleId,
                    Type       = CustomerTransaction.TypePayment
                }).ConfigureAwait(false);
            }

            tx.Complete();
            return(sale);
        }