Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task <TariffDto> Update(TariffUpdateDto request)
        {
            //TODO need implement validator

            using (var db = new ApplicationDbContext())
            {
                var toUpdate = await db.Tariffs.FindAsync(request.Id);

                if (toUpdate == null)
                {
                    throw new InternalExceptions.NotFoundException(request.Id.ToString());
                }

                toUpdate.Name       = request.Name;
                toUpdate.Comment    = request.Comment;
                toUpdate.IsPeriodic = request.IsPeriodic;
                toUpdate.Type       = (TariffType)request.Type;
                toUpdate.InputRate  = request.InputRate;
                toUpdate.OutputRate = request.OutputRate;

                var result = db.Tariffs.Update(toUpdate);
                await db.SaveChangesAsync();

                return(_mapper.ToDto(result.Entity));
            }
        }
        public async Task <JsonResult> Tariff([FromBody] TariffUpdateDto request)
        {
            var result = await _service.Update(request);

            return(Json(result));
        }