예제 #1
0
        private async Task ValidateIfExist(RemmittanceModel remmittanceModel)
        {
            var existingEntity = await _remmittanceRepository.GetByIdAsync(remmittanceModel.Id);

            if (existingEntity != null)
            {
                throw new ApplicationException("Remmittance with this id already exists.");
            }
        }
예제 #2
0
        public async Task <ActionResult <RemmittanceModel> > PostRemmittance(RemmittanceModel remmittanceModel)
        {
            if (remmittanceModel == null)
            {
                return(BadRequest());
            }

            var created = await _remmittanceService.Create(remmittanceModel);

            return(CreatedAtAction("GetRemmittance", new { id = created.Id }, created));
        }
예제 #3
0
        public async Task <RemmittanceModel> Create(RemmittanceModel remmittanceModel)
        {
            await ValidateIfExist(remmittanceModel);

            try
            {
                var mappedEntity = ObjectMapper.Mapper.Map <Remittance>(remmittanceModel);
                if (mappedEntity == null)
                {
                    throw new ApplicationException($"Entity could not be mapped.");
                }

                var newEntity = await _remmittanceRepository.Create(mappedEntity);

                _logger.LogInformation($"Entity successfully added.");

                var newMappedEntity = ObjectMapper.Mapper.Map <RemmittanceModel>(newEntity);
                return(newMappedEntity);
            }
            catch (Exception)
            {
                return(null);
            }
        }