Beispiel #1
0
 public static CodeTransactionDTO ToCodeTransactionDTO(this MCodeTransaction entityCodeTransaction)
 {
     return((entityCodeTransaction == null)
                 ? new CodeTransactionDTO()
                 : new CodeTransactionDTO()
     {
         ID = entityCodeTransaction.ID,
         Code = entityCodeTransaction.Code
     });
 }
Beispiel #2
0
        public async Task <int> DeleteTransactionCode(uint id)
        {
            _cache.ClearValues(KEY_CACHE_CODES);

            MCodeTransaction mCodeTransaction = this._contextDB.MCodeTransaction.Where(x => x.ID == id).SingleOrDefault();

            if (mCodeTransaction == null)
            {
                throw new Exception($"Code ID: {id} not found!");
            }

            int transactionCodesInUse = this._contextDB.TransactionOutlay.Where(x => x.CodeTransaction_ID == mCodeTransaction.ID).Count();

            if (transactionCodesInUse > 0)
            {
                throw new Exception("Not possible delete due to is being using in a transactions");
            }

            this._contextDB.Context.Remove(mCodeTransaction);
            await this._contextDB.Context.SaveChangesAsync();

            return(mCodeTransaction.ID);
        }
Beispiel #3
0
        public async Task <int> AddTransactionCode(CodeTransactionDTO codeTransactionDTO)
        {
            _cache.ClearValues(KEY_CACHE_CODES);

            string transactionCodeFormat = codeTransactionDTO.Code.ToUpperInvariant().Trim();

            HashSet <string> codesAvailables = this._contextDB.MCodeTransaction.Select(x => x.Code).ToHashSet();

            if (codesAvailables.Contains(transactionCodeFormat))
            {
                throw new Exception($"The code {transactionCodeFormat} already exist!");
            }

            MCodeTransaction mCodeTransaction = new MCodeTransaction()
            {
                Code = transactionCodeFormat
            };

            await this._contextDB.MCodeTransaction.AddAsync(mCodeTransaction);

            await this._contextDB.Context.SaveChangesAsync();

            return(mCodeTransaction.ID);
        }