コード例 #1
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }