public ActionResult <IEnumerable <Patient> > AddFromExcel([FromBody] IEnumerable <ExcelPatient> patientsList) { var countryList = _repository.GetCountries(); var correctPatients = new List <Patient>(); foreach (var patient in patientsList) { //1. Check Country var country = countryList.Find(c => c.Name == patient.Nacionalidad); if (country != null) {// Does not accepted //1.2. Country Code and region var patientCountry = country.Code; var regionList = _repository.GetRegions(patientCountry); if (regionList.Count != 0) { var patientRegion = regionList[0].Name; // Gets the first Region --> No complications DateTime patientDoB; try { //2. Cast Date patientDoB = DateTime.Parse(patient.FechaNacimiento); } catch (System.FormatException) { patientDoB = DateTime.Today; } //3. Name se va como Tal var patientName = patient.Nombre; //4. Identificacion juega var patientDni = patient.Identificación; var new_patient = new Patient() { Dni = patientDni, Name = patientName, LastName = "", DoB = patientDoB, Status = 2, // INFECTED Hospital_Id = 8, // Default Hospital Region = patientRegion, Country = patientCountry }; _repository.CreatePatient(new_patient); _repository.SaveChanges(); correctPatients.Add(new_patient); } } } return(Ok(correctPatients)); }