public List <UserInformation> GetAll() { var json = JsonFileUtilities.ReadData("UserInformation"); var data = JsonSerializer.Deserialize <List <UserInformation> >(json, JsonFileUtilities.SerializerOptions); return(data); }
public CudResponse Create(UserInformation user) { try { var allUsers = GetAll(); allUsers.Add(user); JsonFileUtilities.WriteToFile <UserInformation>("UserInformation", allUsers); return(new CudResponse { Id = 0, Status = 0 }); } catch { return(new CudResponse { Id = 1, Status = -1 }); } }
public CudResponse Create(TaskInformation task) { try { var allTasks = GetAll(); allTasks.Add(task); JsonFileUtilities.WriteToFile <TaskInformation>("TaskInformation", allTasks); return(new CudResponse { Id = 0, Status = 0 }); } catch { return(new CudResponse { Id = 1, Status = -1 }); } }
public static void PerformDataCreation() { Console.WriteLine("Please enter a model name to serialize"); var modelName = Console.ReadLine(); Console.WriteLine("If you want to build a list, please enter the size, otherwise just press enter"); var sizeEntered = Console.ReadLine(); var listSize = 0; if (string.IsNullOrWhiteSpace(sizeEntered) || Int32.TryParse(sizeEntered, out listSize)) { Console.WriteLine($"A list will be created for {modelName}"); } else { Console.WriteLine($"A single object will be created for {modelName}"); } try { switch (modelName) { case "TaskInformation": var taskData = Seeder.GetTaskInformationList(listSize); JsonFileUtilities.WriteToFile <TaskInformation>("TaskInformation", taskData); break; case "UserInformation": var userData = Seeder.GetUserInformationList(listSize); JsonFileUtilities.WriteToFile <UserInformation>("UserInformation", userData); break; case "TaskResult": var taskResultData = Seeder.GetListOf <TaskResult>(listSize); JsonFileUtilities.WriteToFile <TaskResult>("TaskResult", taskResultData); break; } Console.WriteLine("File Created"); } catch (Exception ex) { Console.WriteLine(ex); } }
public CudResponse Delete(int id) { try { var allUsers = GetAll(); //remove the user information object with the provided id and recreate the file allUsers.RemoveAll(x => x.Id == id); JsonFileUtilities.WriteToFile <UserInformation>("UserInformation", allUsers); return(new CudResponse { Id = 0, Status = 0 }); } catch { return(new CudResponse { Id = 2, Status = -1 }); } }
public CudResponse Delete(int id) { try { var allTasks = GetAll(); //remove the task object with the provided id and recreate the file allTasks = allTasks.Where(x => x.Id != id).ToList(); JsonFileUtilities.WriteToFile <TaskInformation>("TaskInformation", allTasks); return(new CudResponse { Id = 0, Status = 0 }); } catch (System.Exception ex) { return(new CudResponse { Id = 2, Status = -1 }); } }
public CudResponse Update(UserInformation user) { try { var allUsers = GetAll(); //find and replace the old user information object with the new one and recreate the file var oldUser = allUsers.FirstOrDefault(x => x.Id == user.Id); var index = allUsers.IndexOf(oldUser); if (index != -1) { allUsers[index] = user; } JsonFileUtilities.WriteToFile <UserInformation>("UserInformation", allUsers); return(new CudResponse { Id = 0, Status = 0 }); } catch { return(new CudResponse { Id = 2, Status = -1 }); } }
public CudResponse Update(TaskInformation task) { try { var allTasks = GetAll(); //find and replace the old task object with the new one and recreate the file var oldTask = allTasks.FirstOrDefault(x => x.Id == task.Id); var index = allTasks.IndexOf(oldTask); if (index != -1) { allTasks[index] = task; } JsonFileUtilities.WriteToFile <TaskInformation>("TaskInformation", allTasks); return(new CudResponse { Id = 0, Status = 0 }); } catch { return(new CudResponse { Id = 2, Status = -1 }); } }