/// <summary> /// method that location to database /// </summary> /// <param name="location"></param> /// <returns></returns> public tblLOCATION AddLocation(tblLOCATION location) { try { using (EmployeeDBEntities context = new EmployeeDBEntities()) { tblLOCATION newLocation = new tblLOCATION(); newLocation.Adress = location.Adress; newLocation.Country = location.Country; newLocation.Place = location.Place; context.tblLOCATIONs.Add(newLocation); context.SaveChanges(); location.LocationID = newLocation.LocationID; //FileLoging fileLog = FileLoging.Instance(); //fileLog.LogAddLocationToFile(location); return(location); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString()); return(null); } }
public AddEmployeViewModel(AddEmploye addEmployeOpen) { addEmploye = addEmployeOpen; LocationList = GetLocations(); GenderList = GetGenders(); Location = new tblLOCATION(); Gender = new tblGender(); Employe = new tblEmploye(); Sector = new tblSector(); }
public List <tblLOCATION> GetLocations() { string path = @"../../Locations.txt"; StreamReader sr = new StreamReader(path); string line = ""; List <string> locations = new List <string>(); while ((line = sr.ReadLine()) != null) { locations.Add(line); } sr.Close(); List <tblLOCATION> locationList = new List <tblLOCATION>(); context context = new context(); for (int i = 0; i < locations.Count; i++) { tblLOCATION oneLocation = new tblLOCATION(); List <string> adressList = new List <string>(); adressList = locations[i].Split(',').ToList(); oneLocation.Adress = adressList[0]; oneLocation.Place = adressList[1]; oneLocation.States = adressList[2]; locationList.Add(oneLocation); } if (context.tblLOCATIONS.Count() == 0) { for (int i = 0; i < locationList.Count; i++) { context.tblLOCATIONS.Add(locationList[i]); } } context.SaveChanges(); return(locationList); }