public PolizasEntity Add(PolizasEntity model)
        {
            Polizas poliza  = null;
            var     config  = new MapperConfiguration(cfg => cfg.CreateMap <PolizasEntity, Polizas>());
            IMapper iMapper = config.CreateMapper();

            poliza = iMapper.Map <PolizasEntity, Polizas>(model);
            try
            {
                if (db.Polizas.Find(poliza.id) == null)
                {
                    db.Polizas.Add(poliza);
                }
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbUpdateConcurrencyException, ex);
            }
            catch (DbUpdateException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbUpdateException, ex);
            }
            catch (DbEntityValidationException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbEntityValidationException, ex);
            }
            catch (NotSupportedException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.NotSupportedException, ex);
            }
            catch (ObjectDisposedException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.ObjectDisposedException, ex);
            }
            catch (InvalidOperationException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.InvalidOperationException, ex);
            }
            return(model);
        }
Beispiel #2
0
        public ClientesEntity Add(ClientesEntity model)
        {
            Clientes cliente = null;
            IMapper  iMapper = RepositoryConfigAutomapper.configEscribir.CreateMapper();

            cliente = iMapper.Map <ClientesEntity, Clientes>(model);

            try
            {
                if (db.Clientes.Find(cliente.id) == null)
                {
                    db.Clientes.Add(cliente);
                }
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbUpdateConcurrencyException, ex);
            }
            catch (DbUpdateException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbUpdateException, ex);
            }
            catch (DbEntityValidationException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.DbEntityValidationException, ex);
            }
            catch (NotSupportedException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.NotSupportedException, ex);
            }
            catch (ObjectDisposedException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.ObjectDisposedException, ex);
            }
            catch (InvalidOperationException ex)
            {
                VuelingLogger.Logger(ex);
                throw new VuelingException(Resources.InvalidOperationException, ex);
            }
            return(model);
        }
        public IHttpActionResult Post(ClientesDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ClientesDto clienteDtoInsert = null;

            try
            {
                clienteDtoInsert = clientesService.Add(model);
            }
            catch (VuelingException ex)
            {
                VuelingLogger.Logger(ex);
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return(CreatedAtRoute("DefaultApi",
                                  new { id = clienteDtoInsert.id }, clienteDtoInsert));
        }