/// <summary> /// Ajoute une entreprise avec tous ses contacts /// </summary> /// <param name="entreprise">entreprise à ajouter</param> /// <param name="document">document à modifier</param> public static void addEntreprise(ViewModel.Entreprise entreprise, string document) { List <ViewModel.Employee> emps = entreprise.Contacts; System.IO.File.WriteAllText(document, entreprise.toModels().toCSV()); }
/// <summary> /// Modifie une entreprise existante /// </summary> /// <param name="entreprise">entreprise à modifier</param> /// <param name="document">document à modifier</param> public static bool modifyEntreprise(ViewModel.Entreprise entreprise, string document) { if (entreprise.ID != 0 && removeEntreprise(entreprise.ID, document)) { addEntreprise(entreprise, document); return(true); } return(false); }
/// <summary> /// Ajoute une entreprise avec tous ses contacts /// </summary> /// <param name="entreprise">entreprise à ajouter</param> /// <param name="document">document à modifier</param> public static void addEntreprise(ViewModel.Entreprise entreprise, string document) { List <string> fileContent = System.IO.File.ReadAllLines(document).ToList(); List <ViewModel.Employee> emps = entreprise.Contacts; int i; int id = 1; // Add Entreprise for (i = 0; i < fileContent.Count && fileContent[i].Trim(new Char[] { Delimitter }) != "<ENTREPRISES>"; i++) { } for (i++; i < fileContent.Count && fileContent[i].Trim(new Char[] { Delimitter }) != ""; i++) { int curr_id = int.Parse(fileContent[i].Split(Delimitter)[0]); if (id <= curr_id) { id = curr_id + 1; } } if (i >= fileContent.Count) { return; } entreprise.ID = id; fileContent.Insert(i, entreprise.toModels().toCSV()); // Add contacts for (i++; i < fileContent.Count && fileContent[i].Trim(new Char[] { Delimitter }) != "<CONTACTS>"; i++) { } for (i++; i < fileContent.Count && fileContent[i].Trim(new Char[] { Delimitter }) != ""; i++) { } List <string> lst_contacts = new List <string>(); for (int j = 0; j < entreprise.Contacts.Count; j++) { lst_contacts.Add(entreprise.Contacts[j].toModel().toCSV()); } fileContent.InsertRange(i, lst_contacts); System.IO.File.WriteAllLines(document, fileContent); }
public void Put(int id, [FromBody] ViewModel.Entreprise entreprise) { Services.IO.modifyEntreprise(entreprise, Services.IO.Document); }
public void Post([FromBody] ViewModel.Entreprise entreprise) { Services.IO.addEntreprise(entreprise, Services.IO.Document); }