Ejemplo n.º 1
0
        public async Task <FeeViewModel> AddAsync(FeeCreateModel cm)
        {
            try
            {
                var max = await base.MaxAsync(x => new FeeViewModel {
                    Id = x.Id
                });

                cm.Id = (short)(max == null ? 1 : ++max.Id);

                var em = Mapper.Map <Fee>(cm);
                var ok = await base.AddAsync(em);

                if (ok)
                {
                    return(await base.FindAsync(x => new FeeViewModel
                    {
                        Id = em.Id,
                        Percent = em.Percent,
                        CoinName = x.Coin.Name,
                        OnCreated = x.OnCreated
                    }, predicate : x => x.Id == em.Id));
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message, cm);
                throw;
            }

            return(new FeeViewModel());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] FeeCreateModel cm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vm = await this.service.AddAsync(cm);

            return(Ok(vm));
        }