public async Task <string> Add(ITransaction entity)
        {
            var entityDTO = _transactionConverter.Convert(entity);
            await _collection.InsertOneAsync(entityDTO);

            var result = await _collection.FindAsync(e => true);

            return(result.ToList().Last().Id);
        }
示例#2
0
        public async Task CreateAsync(Transaction entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            var transaction = TransactionConverter.Convert(entity);

            await _session.InsertAsync(transaction);
        }
        public ServiceResponse <List <TransactionModel> > List()
        {
            var response             = new ServiceResponse <List <TransactionModel> >();
            var transactionConverter = new TransactionConverter();
            var serviceResponse      = _transactionService.ListForUser(CurrentUser.ID);

            if (serviceResponse.IsSuccessed)
            {
                response.Data = transactionConverter.Convert(serviceResponse.Data);
            }
            response.IsSuccessed = serviceResponse.IsSuccessed;
            return(response);
        }
        public void ConvertTest()
        {
            var converter = new TransactionConverter();

            string[] values =
            {
                "1000",
                "Title",
                "Category"
            };

            var transation = converter.Convert(values, typeof(Transaction), null,
                                               System.Globalization.CultureInfo.CurrentCulture) as Transaction;

            Assert.AreEqual(transation.Value.ToString(), values[0]);
            Assert.AreEqual(transation.Title, values[1]);
            Assert.AreEqual(transation.Category, values[2]);
        }
示例#5
0
        public async Task <Transaction> GetAsync(Guid id)
        {
            var transaction = await _session.Query <Models.Transaction>()
                              .Where(t => t.Id == id.ToString())
                              .Select(t => new Models.Transaction
            {
                Id       = t.Id,
                Date     = t.Date,
                Amount   = t.Amount,
                Category = t.Category
            })
                              .FirstOrDefaultAsync();

            if (transaction == null)
            {
                return(null);
            }

            return(TransactionConverter.Convert(transaction));
        }