示例#1
0
            int IComparer.Compare(object a, object b)
            {
                PersonaModel p1 = (PersonaModel)a;
                PersonaModel p2 = (PersonaModel)b;

                if (String.Compare(p1.apellido, p2.apellido) < 1)
                {
                    return(1);
                }

                if (String.Compare(p1.apellido, p2.apellido) > 1)
                {
                    return(-1);
                }

                else
                {
                    if (String.Compare(p1.nombre, p2.nombre) < 1)
                    {
                        return(1);
                    }

                    if (String.Compare(p1.nombre, p2.nombre) > 1)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
示例#2
0
        public bool UpdatePersona(int idPersona, BusinessEntities.PersonaModel personaModel)
        {
            var success    = false;
            var EFPersonas = context.Set <EFPersona>();

            if (personaModel != null)
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    var EFPersona = EFPersonas.Where(p => p.id == idPersona).FirstOrDefault <EFPersona>();
                    if (EFPersona != null)
                    {
                        EFPersona.apellido        = personaModel.apellido;
                        EFPersona.nombre          = personaModel.nombre;
                        EFPersona.numeroDocumento = personaModel.numeroDocumento;
                        EFPersona.cuit            = personaModel.cuit;
                        EFPersona.idTipoPersona   = EFPersona.idTipoPersona;
                        EFPersona.idTipoDocumento = personaModel.idTipoDocumento;
                        EFPersona.idTipoSociedad  = EFPersona.idTipoSociedad;
                        EFPersona.fechaAlta       = personaModel.fechaAlta;
                        //Mapper.Map<BusinessEntities.PersonaModel, EFPersona>(personaModel, EFPersona);
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                        {
                            Exception raise = dbEx;
                            foreach (var validationErrors in dbEx.EntityValidationErrors)
                            {
                                foreach (var validationError in validationErrors.ValidationErrors)
                                {
                                    string message = string.Format("{0}:{1}",
                                                                   validationErrors.Entry.Entity.ToString(),
                                                                   validationError.ErrorMessage);
                                    // raise a new exception nesting
                                    // the current instance as InnerException
                                    raise = new InvalidOperationException(message, raise);
                                }
                            }
                            throw raise;
                        }
                        transaction.Commit();
                        success = true;
                    }
                }
            }
            return(success);
        }
示例#3
0
        public int CreatePersonas(BusinessEntities.PersonaModel personaModel)
        {
            using (var transaction = context.Database.BeginTransaction())
            {
                var persona    = Mapper.Map <BusinessEntities.PersonaModel, EFPersona>(personaModel);
                var EFPersonas = context.Set <EFPersona>();
                try
                {
                    EFPersonas.Add(persona);
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        Exception raise = dbEx;
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                string message = string.Format("{0}:{1}",
                                                               validationErrors.Entry.Entity.ToString(),
                                                               validationError.ErrorMessage);
                                // raise a new exception nesting
                                // the current instance as InnerException
                                raise = new InvalidOperationException(message, raise);
                            }
                        }
                        throw raise;
                    }
                    transaction.Commit();
                    return(persona.id);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.InnerException.Message);

                    transaction.Rollback();
                }
                return(0);
            }
        }