コード例 #1
0
        public void ActualizarTipoGasto(Modelos.TiposDeGastosDTO tipodegastosdto)
        {
            using (ControlPersonalEntities2 contexto = new ControlPersonalEntities2())
            {
                var tipogasto = contexto.TiposdeGastos.FirstOrDefault(x => x.IdTipoGasto == tipodegastosdto.IdTipoGasto);

                if (tipogasto != null)
                {
                    tipogasto.DescripcionGasto = tipodegastosdto.DescripcionGasto;
                    contexto.SaveChanges();
                }
            }
        }
コード例 #2
0
        public void AgregarTipogastos(Modelos.TiposDeGastosDTO tipogastosDTO)
        {
            try
            {
                using (ControlPersonalEntities2 contexto = new ControlPersonalEntities2())
                {
                    var nuevoTipogasto = new TiposdeGastos();

                    nuevoTipogasto.DescripcionGasto = tipogastosDTO.DescripcionGasto;
                    nuevoTipogasto.UsuarioAlta      = "";
                    nuevoTipogasto.FechaAlta        = DateTime.Now;
                    nuevoTipogasto.IdTipoGasto      = Guid.NewGuid();
                    contexto.TiposdeGastos.Add(nuevoTipogasto);
                    contexto.SaveChanges();
                }
            }

            catch (DbEntityValidationException ex)
            {
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            catch (DbUpdateException ex)
            {
                //HandleDbUpdateException(ex);

                string mesage = ex.Message;
            }
        }