Пример #1
0
        public void ModificarAgresor(Agresor agresor)
        {
            if (agresor == null)
            {
                throw new FaultException(Lenguaje.AgresorNoExiste);
            }

            var agresorModificar = RepositorioAgresores.DevolverPorId(agresor.Id);

            if (agresorModificar == null)
            {
                throw new FaultException(Lenguaje.AgresorNoExiste);
            }
            if (agresorModificar.EstaBorrado)
            {
                throw new FaultException(Lenguaje.AgresorYaEliminado);
            }
            if (string.IsNullOrWhiteSpace(agresor.Nombre) &
                string.IsNullOrWhiteSpace(agresor.Apellido) &
                string.IsNullOrWhiteSpace(agresor.Apodo))
            {
                throw new FaultException(Lenguaje.AgresorSinNombreApellidoApodo);
            }

            if (string.IsNullOrEmpty(agresor.Nombre))
            {
                agresor.Nombre = string.Empty;
            }
            if (string.IsNullOrEmpty(agresor.Apellido))
            {
                agresor.Apellido = string.Empty;
            }
            if (string.IsNullOrEmpty(agresor.Apodo))
            {
                agresor.Apodo = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(agresor.Ocupacion))
            {
                throw new FaultException(Lenguaje.OcupacionNoValida);
            }
            if (string.IsNullOrWhiteSpace(agresor.Metodos))
            {
                throw new FaultException(Lenguaje.MetodosNoValidos);
            }
            if (string.IsNullOrWhiteSpace(agresor.Caracteristicas))
            {
                throw new FaultException(Lenguaje.CaracteristicasNoValidas);
            }
            agresorModificar.Nombre          = agresor.Nombre.Trim();
            agresorModificar.Apellido        = agresor.Apellido.Trim();
            agresorModificar.Apodo           = agresor.Apodo.Trim();
            agresorModificar.Ocupacion       = agresor.Ocupacion.Trim();
            agresorModificar.Metodos         = agresor.Metodos.Trim();
            agresorModificar.Direcciones     = agresor.Direcciones;
            agresorModificar.RedesSociales   = agresor.RedesSociales;
            agresorModificar.Telefonos       = agresor.Telefonos;
            agresorModificar.Caracteristicas = agresor.Caracteristicas.Trim();

            if (agresor.Telefonos != null)
            {
                foreach (var item in agresor.Telefonos)
                {
                    item.Localidad = RepositorioLocalidades.DevolverPorId(item.Localidad.Id);
                    if (item.Localidad == null)
                    {
                        throw new FaultException(Lenguaje.LocalidadNoValida);
                    }

                    item.Tipo = RepositorioTiposTelefonos.DevolverPorId(item.Tipo.Id);
                    if (item.Tipo == null)
                    {
                        throw new FaultException(Lenguaje.TipoTelefonoNoValido);
                    }

                    if (string.IsNullOrWhiteSpace(item.Numero))
                    {
                        throw new FaultException(Lenguaje.NumeroNoValido);
                    }
                }
            }

            if (agresor.Direcciones != null)
            {
                foreach (var item in agresor.Direcciones)
                {
                    item.Localidad = RepositorioLocalidades.DevolverPorId(item.Localidad.Id);
                    if (item.Localidad == null)
                    {
                        throw new FaultException(Lenguaje.LocalidadNoValida);
                    }

                    item.Tipo = RepositorioTiposDirecciones.DevolverPorId(item.Tipo.Id);
                    if (item.Tipo == null)
                    {
                        throw new FaultException(Lenguaje.TipoDireccionNoValido);
                    }
                    if (string.IsNullOrWhiteSpace(item.Calle))
                    {
                        throw new FaultException(Lenguaje.CalleNoValida);
                    }
                    if (string.IsNullOrWhiteSpace(item.Numero))
                    {
                        throw new FaultException(Lenguaje.NumeroNoValido);
                    }
                    switch ((EnumTiposDirecciones)item.Tipo.Id)
                    {
                    case EnumTiposDirecciones.Departamento:
                        if (string.IsNullOrWhiteSpace(item.Departamento) | item.Departamento.Length > 4)
                        {
                            throw new FaultException(Lenguaje.DepartamentoNoValido);
                        }
                        if (string.IsNullOrWhiteSpace(item.Piso) | item.Piso.Length > 3)
                        {
                            throw new FaultException(Lenguaje.PisoNoValido);
                        }
                        break;

                    default:
                        item.Departamento = string.Empty;
                        item.Piso         = string.Empty;
                        break;
                    }
                }
            }

            if (agresor.RedesSociales != null)
            {
                foreach (var item in agresor.RedesSociales)
                {
                    item.Tipo = RepositorioTiposRedesSociales.DevolverPorId(item.Tipo.Id);
                    if (item.Tipo == null)
                    {
                        throw new FaultException(Lenguaje.TipoRedSocialNoValido);
                    }

                    if (string.IsNullOrEmpty(item.Nombre))
                    {
                        throw new FaultException(Lenguaje.NombreNoValido);
                    }
                }
            }

            RepositorioAgresores.Modificar(agresorModificar);

            RepositorioAgresores.EliminarTelefonoPorAgresor(agresorModificar);
            if (agresorModificar.Telefonos != null)
            {
                foreach (var item in agresorModificar.Telefonos)
                {
                    RepositorioAgresores.InsertarTelefono(item, agresorModificar);
                }
            }

            RepositorioAgresores.EliminarDireccionPorAgresor(agresorModificar);
            if (agresorModificar.Direcciones != null)
            {
                foreach (var item in agresorModificar.Direcciones)
                {
                    RepositorioAgresores.InsertarDireccion(item, agresorModificar);
                }
            }

            RepositorioAgresores.EliminarRedSocialPorAgresor(agresorModificar);
            if (agresorModificar.RedesSociales != null)
            {
                foreach (var item in agresorModificar.RedesSociales)
                {
                    RepositorioAgresores.InsertarRedSocial(item, agresorModificar);
                }
            }
        }
Пример #2
0
 public List <TipoTelefono> DevolverTiposTelefonos()
 {
     return(RepositorioTiposTelefonos.DevolverTodos());
 }