private void EditWorker(string payload, StreamWriter clientWriter) { EditWorkerRequest request = JsonSerializer.Deserialize <EditWorkerRequest>(payload); Worker newWorker = request.NewWorker; List <Worker> workers = ReadWorkersFromFile(); for (int i = 0; i < workers.Count; i++) { if (workers[i].Name.Equals(request.OldName)) { workers[i] = newWorker; } } WorkersArray arr = new WorkersArray() { Workers = workers }; clientWriter.WriteLine(JsonSerializer.Serialize(arr)); clientWriter.Flush(); string workersStr = JsonSerializer.Serialize(workers); workersStr = ""; workers.ForEach(worker => { workersStr += JsonSerializer.Serialize(worker) + "\n"; }); File.WriteAllText(@"E:\Лабы\7 сем\рис\Lab3\Lab3Server\text.txt", workersStr); }
private void DeleteWorker(string name, StreamWriter clientWriter) { List <Worker> workers = ReadWorkersFromFile(); workers = workers.FindAll(worker => !worker.Name.Equals(name)); WorkersArray arr = new WorkersArray() { Workers = workers }; string workersStr = JsonSerializer.Serialize(arr); clientWriter.WriteLine(workersStr); clientWriter.Flush(); workersStr = ""; workers.ForEach(worker => { workersStr += JsonSerializer.Serialize(worker) + "\n"; }); File.WriteAllText(@"E:\Лабы\7 сем\рис\Lab3\Lab3Server\text.txt", workersStr); }
private void GetWorkers(StreamWriter clientWriter) { List <Worker> workers = ReadWorkersFromFile(); WorkersArray arr = new WorkersArray() { Workers = workers }; clientWriter.WriteLine(JsonSerializer.Serialize(arr)); clientWriter.Flush(); }
private void SearchWorker(string payload, StreamWriter clientWriter) { List <Worker> workers = ReadWorkersFromFile(); workers = workers.FindAll(worker => worker.Name.Contains(payload)); WorkersArray arr = new WorkersArray() { Workers = workers }; clientWriter.WriteLine(JsonSerializer.Serialize(arr)); clientWriter.Flush(); }
private void SortBySalary(StreamWriter clientWriter) { List <Worker> workers = ReadWorkersFromFile(); IEnumerable <Worker> query = workers.OrderBy(worker => worker.Salary); workers = query.ToList(); WorkersArray arr = new WorkersArray() { Workers = workers }; clientWriter.WriteLine(JsonSerializer.Serialize(arr)); clientWriter.Flush(); }