예제 #1
0
        public async Task <IActionResult> Save([FromBody] WalletChangeDTO dto)
        {
            if (dto != null && ModelState.IsValid)
            {
                var entity = new WalletValueChange();
                BuildEntity(entity, dto);
                await _db.WalletValueChanges.AddAsync(entity);

                await _db.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
예제 #2
0
        private void BuildEntity(WalletValueChange entity, WalletChangeDTO dto)
        {
            if (entity == null || dto == null)
            {
                return;
            }

            switch (dto.OperationType)
            {
            case OperationType.outcome:
                entity.ChangeValue = -dto.Value;
                break;

            case OperationType.income:
                entity.ChangeValue = dto.Value;
                break;
            }
            entity.Date        = DateTime.Now;
            entity.WalletId    = dto.WalletId;
            entity.Description = dto.Description;
            entity.CategoryId  = dto.CategoryId;
            entity.CategoryId  = dto.CategoryId;
        }