Exemple #1
0
        public PersonaBE CreateBusiness(DataModel.personas entity)
        {
            PersonaBE be;

            if (entity != null)
            {
                be = new PersonaBE()
                {
                    id_persona   = entity.id_persona,
                    id_plan      = entity.id_plan,
                    apellido     = entity.apellido,
                    nombre       = entity.nombre,
                    direccion    = entity.direccion,
                    fecha_nac    = entity.fecha_nac,
                    legajo       = entity.legajo,
                    telefono     = entity.telefono,
                    tipo_persona = entity.tipo_persona,
                    estado       = entity.estado
                };
                be.Usuarios = new List <UsuarioBE>();
                if (entity.usuarios != null)
                {
                    foreach (var item in entity.usuarios)
                    {
                        be.Usuarios.Add(FactoryUsuario.GetInstance().CreateBusiness(item));
                    }
                }
                return(be);
            }
            return(be = new PersonaBE());
        }
Exemple #2
0
 public DataModel.personas CreateEntity(PersonaBE be)
 {
     DataModel.personas entity;
     if (be != null)
     {
         entity = new DataModel.personas()
         {
             id_persona   = be.id_persona,
             id_plan      = be.id_plan,
             apellido     = be.apellido,
             nombre       = be.nombre,
             direccion    = be.direccion,
             fecha_nac    = be.fecha_nac,
             legajo       = be.legajo,
             telefono     = be.telefono,
             tipo_persona = be.tipo_persona,
             estado       = be.estado
         };
         entity.usuarios = new List <DataModel.usuarios>();
         if (entity.usuarios != null)
         {
             foreach (var item in be.Usuarios)
             {
                 entity.usuarios.Add(FactoryUsuario.GetInstance().CreateEntity(item));
             }
         }
         return(entity);
     }
     return(entity = new DataModel.personas());
 }
        public long Create(PersonaBE Be)
        {
            try
            {
                if (Be != null)
                {
                    Be.legajo = GetLastLegajo();
                    Be.Usuarios[0].nombre_usuario = GetLastLegajo().ToString();
                    if (TypeUser.GetInstance().GetTyperUser(Be.tipo_persona) == 1 || TypeUser.GetInstance().GetTyperUser(Be.tipo_persona) == 2)
                    {
                        Be.id_plan = 20;
                    }

                    DataModel.personas entity = Factory.FactoryPersona.GetInstance().CreateEntity(Be);

                    Expression <Func <DataModel.personas, Boolean> > predicate = x => (x.telefono == entity.telefono);
                    DataModel.personas verify = _unitOfWork.PersonaRepository.GetOneByFilters(predicate, new string[] { "usuarios.modulos_usuarios" });
                    if (verify != null)
                    {
                        throw new ApiBusinessException(1012, "Ya existe un usuario con ese numero de telefono", System.Net.HttpStatusCode.Forbidden, "Http");
                    }

                    var email = entity.usuarios.FirstOrDefault().email.ToString();
                    Expression <Func <DataModel.usuarios, Boolean> > predicateuser = x => (x.email == email);
                    DataModel.usuarios usur = _unitOfWork.UsuarioRepository.GetOneByFilters(predicateuser, new string[] { "modulos_usuarios" });
                    if (usur != null)
                    {
                        throw new ApiBusinessException(1012, "Ya existe un usuario con ese email", System.Net.HttpStatusCode.Forbidden, "Http");
                    }

                    _unitOfWork.PersonaRepository.Insert(entity);
                    _unitOfWork.Commit();
                    return(entity.id_persona);
                }
                else
                {
                    throw new ApiBusinessException(1012, "No se pudo crear el plan", System.Net.HttpStatusCode.NotFound, "Http");
                }
            }
            catch (Exception ex)
            {
                throw HandlerErrorExceptions.GetInstance().RunCustomExceptions(ex);
            }
        }