public bool Registrar(Conductor obj) { if (!String.IsNullOrWhiteSpace(obj.Dni)) { if (!conductorRepository.Exists(obj.Dni)) { //Si tiene DNI, debe tener persona if (!String.IsNullOrWhiteSpace(obj.Dni)) { if (obj.DniNavigation is null)//si no tiene, la creo { obj.DniNavigation = new Persona() { Dni = obj.Dni, Tipo = "con" }; } else { obj.DniNavigation.Dni = obj.Dni; obj.DniNavigation.Tipo = "con"; } PersonaRepository personaRepository = new PersonaRepository(); if (!personaRepository.Exists(obj.DniNavigation.Dni)) { personaRepository.Insert(obj.DniNavigation); } } //Primero verifico si se agrego de manera correcta a la DB, luego lo agrego a la Lista in Memory var Result = conductorRepository.Insert(obj); return(Result); } else { throw new Exception(ExceptionMessageManager.ExceptionMessageConductor.AlreadyExists(obj.Dni)); } } else { throw new Exception(ExceptionMessageManager.ExceptionMessageConductor.KeyIsNull()); } }
public static void Insert(Conductor obj) { repository.Insert(obj); }