public async Task <JsonResult> AddPaymentCode(PaymentCodeViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(JsonModelStateErrors());
     }
     return(await JsonAsync(_paymentCodeService.AddPaymentCodeAsync(model)));
 }
        /// <summary>
        /// Add payment code
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddPaymentCodeAsync(PaymentCodeViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }


            var paymentCode = _mapper.Map <PaymentCode>(model);

            await _context.PaymentCodes.AddAsync(paymentCode);

            var result = await _context.PushAsync();

            return(result.Map(paymentCode.Id));
        }
        /// <summary>
        /// Update payment code
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> UpdatePaymentCodeAsync(PaymentCodeViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel());
            }

            var paymentCode = await _context.PaymentCodes.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (paymentCode == null)
            {
                return(new NotFoundResultModel());
            }

            paymentCode.Code = model.Code;
            paymentCode.Name = model.Name;

            _context.PaymentCodes.Update(paymentCode);
            return(await _context.PushAsync());
        }