/// <summary> /// AT: Remueve una persona desde la coleccion en memoria existente. /// </summary> /// <param name="objDto"></param> /// <returns></returns> public List<PersonDto> DeletePerson(PersonDto objDto) { List<PersonDto> resultCollection = default(List<PersonDto>); if (!object.ReferenceEquals(objDto, null)) { var auxAllPersons = GetAllPersons(); if (!object.ReferenceEquals(auxAllPersons, null) && (auxAllPersons.Any())) { foreach (var person in auxAllPersons) { if (person.RutNumeric.Equals(objDto.RutNumeric) && string.Equals(person.RutDiv, objDto.RutDiv, StringComparison.InvariantCultureIgnoreCase)) { if(auxAllPersons.Remove(person) ) { resultCollection = auxAllPersons; } break; } } } } return resultCollection; }
/// <summary> /// ATR - 27/08/2015 Inserta una nueva entidad en memoria. /// </summary> /// <param name="objDto"></param> /// <returns></returns> public List<PersonDto> AddNewPerson(PersonDto objDto) { var auxAllRecords = GetAllPersons(); if (!object.ReferenceEquals(objDto, null)) { auxAllRecords.Add(objDto); } return auxAllRecords; }
public List<PersonDto> GetAllPersons() { var allRecords = default(List<PersonDto>); //ATR: Creando nuevas instancias del objeto DTO PersonDto. //Se pretende simular la recepción de éstos datos desde alguna fuente de datos. //ATR: Otras formas de inicializar objetos e instanciar. //var objExample = new PersonDto(); //PersonDto objExample2 = new PersonDto(); //objExample2.LastName = string.Empty; //List<PersonDto> objNadaQueVer = new List<PersonDto>(); //List<PersonDto> resultCollection = new List<PersonDto>(); //foreach (var item in objNadaQueVer.Where(x=> !object.ReferenceEquals(x, null))) //{ // resultCollection.Add(item); //} var objPerson1 = new PersonDto() { LastName = "testLastname1", Name = "name1", RutDiv = "K", RutNumeric = 12345789 }; var objPerson2 = new PersonDto() { LastName = "testLastname2", Name = "name2", RutDiv = "Y", RutNumeric = 987654321 }; var objPerson3 = new PersonDto() { LastName = "testLastname3", Name = "name3", RutDiv = "Z", RutNumeric = 222555444 }; //AT: Recien, en este punto se genera una instancia en el Heap. //Se utiliza un inicializado de colecciones.- allRecords = new List<PersonDto> () { objPerson1, objPerson2, objPerson3 }; //var algo = new List<PersonDto>(); //algo.Add(objPerson1); return allRecords; }
/// <summary> /// ATR - 27/08/2015 - Actualiza una entidad previa existente. /// </summary> /// <param name="objDto"></param> /// <returns></returns> public List<PersonDto> UpdateNewPerson(PersonDto objDto) { var auxAllPersons = default(List<PersonDto>); if (!objDto.Equals(default(PersonDto))) { auxAllPersons = GetAllPersons(); if (!object.ReferenceEquals(auxAllPersons, null)) { if (auxAllPersons.Any()) { var searchedPerson = default(PersonDto); //ATR: Por ahora no usaremos LinqToEntities. foreach (var item in auxAllPersons) { if ( string.Equals(item.RutDiv, objDto.RutDiv, StringComparison.InvariantCultureIgnoreCase) && (item.RutNumeric.Equals(objDto.RutNumeric))) auxAllPersons.Remove(item); auxAllPersons.Add(objDto); break; } } } } return auxAllPersons; }