Exemple #1
0
        public IHttpActionResult eliminarUbigeo(UbigeoRequest model)
        {
            UbigeoDataAccess      _ubigeoDataAccess = new UbigeoDataAccess();
            BaseResponse <string> result            = new BaseResponse <string>();

            result = _ubigeoDataAccess.EliminarUbigeo(model);

            return(Ok(result));
        }
        public BaseResponse <string> EditarUbigeo(UbigeoRequest model)
        {
            BaseResponse <string> result = new BaseResponse <string>();

            using (MesaDineroContext context = new MesaDineroContext())
            {
                using (var transaccion = context.Database.BeginTransaction())
                {
                    try
                    {
                        Tb_MD_Ubigeo ubigeo = context.Tb_MD_Ubigeo.Find(model.codigo);
                        if (ubigeo == null)
                        {
                            throw new Exception("Entidad Nula, Registro de Ubigeo no encontrado");
                        }

                        ubigeo.CodPais         = model.codigoPais;
                        ubigeo.CodDepartamento = model.codigoDepartamento;
                        ubigeo.CodProvincia    = model.codigoProvincia;
                        ubigeo.CodDistrito     = model.codigoDistrito;
                        ubigeo.iEstadoRegistro = model.estado;


                        context.SaveChanges();
                        transaccion.Commit();

                        result.success = true;
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                    {
                        #region Error EntityFramework
                        var errorMessages = ex.EntityValidationErrors
                                            .SelectMany(x => x.ValidationErrors)
                                            .Select(x => x.ErrorMessage);

                        var fullErrorMessage = string.Join("; ", errorMessages);

                        result.success = false;
                        result.error   = fullErrorMessage;
                        transaccion.Rollback();
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        result.success = false;

                        transaccion.Rollback();
                        result.error = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                    }
                }
            }

            return(result);
        }