public async Task <Dal.Entities.Delivery> UpdateDelivery(Dal.Entities.Delivery delivery)
        {
            var currentDelivery = await GetDeliveryById(delivery.Id);

            if (currentDelivery.DeliveryStatus != DeliveryStatus.Pending)
            {
                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Message = "Unable update the delivery"
                    }
                });
            }

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(delivery, currentDelivery);

            currentDelivery.DeliveryDate = delivery.DeliveryDate.Date;
            currentDelivery.Updated      = DateTimeOffset.UtcNow;

            await _unitOfWork.SaveChanges();

            return(currentDelivery);
        }
        public async Task <Dal.Entities.WareHouse> UpdateWareHouse(Dal.Entities.WareHouse warehouse)
        {
            Guard.Argument(warehouse, nameof(warehouse)).NotNull();

            await ValidateWareHouse(warehouse);

            var currentWareHouse = await GetWareHouseById(warehouse.Id);

            if (_unitOfWork.WareHouseRepository.GetAll().Any(w => w.Code.ToLower() == warehouse.Code.ToLower() &&
                                                             w.Id != warehouse.Id))
            {
                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Message = $"{warehouse.Code} is already exits"
                    }
                });
            }

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(warehouse, currentWareHouse);

            await _unitOfWork.SaveChanges();

            return(currentWareHouse);
        }
        public async Task <Dal.Entities.Supplier> UpdateSupplier(Dal.Entities.Supplier supplier)
        {
            Guard.Argument(supplier, nameof(supplier)).NotNull();

            await ValidateSupplier(supplier);

            await using var transaction = await _unitOfWork.GetTransaction();

            try
            {
                var currentSupplier = await GetSupplierById(supplier.Id);

                supplier.TrackerCode = currentSupplier.TrackerCode;

                var mapper = ServiceMapper.GetMapper();
                mapper.Map(supplier, currentSupplier);

                await _unitOfWork.SaveChanges();

                var savedSupplier = await GetSupplierById(supplier.Id);

                await _trackerApiService.UpdateCustomerStatus(new UpdateCustomerRequest()
                {
                    Active       = supplier.Active ? "1" : "0",
                    CustomerCode = savedSupplier.TrackerCode,
                    StatusDate   = DateTime.Now,
                    StatusReason = "Update the supplier"
                });

                await transaction.CommitAsync();
            }
            catch (TrackingApiException ex)
            {
                await transaction.RollbackAsync();

                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Code    = string.Empty,
                        Message = $"Unable to create a supplier in tracker side"
                    }
                });
            }
            catch
            {
                await transaction.RollbackAsync();

                throw;
            }

            return(await GetSupplierById(supplier.Id));
        }
Example #4
0
        public async Task <Dal.Entities.Product> UpdateProduct(Dal.Entities.Product product)
        {
            Guard.Argument(product, nameof(Product)).NotNull();

            await ValidateProduct(product);

            var currentProduct = await GetProductById(product.Id);

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(product, currentProduct);

            await _unitOfWork.SaveChanges();

            return(currentProduct);
        }
Example #5
0
        public async Task <Dal.Entities.PurchaseOrder> UpdatePurchaseOrder(Dal.Entities.PurchaseOrder purchaseOrder)
        {
            Guard.Argument(purchaseOrder, nameof(purchaseOrder)).NotNull();

            await ValidatePurchaseOrder(purchaseOrder);

            var currentPurchaseOrder = await GetPurchaseOrderById(purchaseOrder.Id);

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(purchaseOrder, currentPurchaseOrder);

            currentPurchaseOrder.Updated = DateTimeOffset.UtcNow;

            await _unitOfWork.SaveChanges();

            return(currentPurchaseOrder);
        }