예제 #1
0
        public async Task <string> GenerateTransactionCodeByTypeCollectionId(long id)
        {
            TypeCollectionInfor typeCollection = _typeCollectionInforRepository.FindById(id);

            if (typeCollection == null)
            {
                throw new UserException(ErrorStatusReturn.TYPE_COLLECTION_NOT_FOUND);
            }

            await semaphoreSlim.WaitAsync();

            string transactionCodeGenerate = string.Empty;

            try
            {
                transactionCodeGenerate          = CreateTransactionCodeFromPattern(typeCollection);
                typeCollection.LastIncreaseCode += 1;

                _typeCollectionInforRepository.Update(typeCollection);
                _unitOfWork.Commit();
            }
            finally
            {
                semaphoreSlim.Release();
            }

            return(transactionCodeGenerate);
        }
        public CarDTO Insert(CarDTO car)
        {
            var entity = new TypeCollectionInfor()
            {
                CreatedBy        = 1,
                UpdatedBy        = 1,
                LastIncreaseCode = 0,
                Status           = Data.Enums.Status.Active,
            };

            _typeCollectionRepo.Add(entity);
            Car carInsert = Mapper.Map <Car>(car);

            _carRepository.Add(carInsert);
            _unitOfWork.Commit();
            return(car);
        }
        private string CreateTransactionCodeFromPattern(TypeCollectionInfor typeCollection)
        {
            string transactionCode = string.Empty;

            return(string.Format(typeCollection.CodePattern, GetMonthCreateTransaction(), GetYearCreateTransaction(), GetIndexForLastNumber(typeCollection.LastIncreaseCode)));
        }