Ejemplo n.º 1
0
Archivo: user.cs Proyecto: groshik/curs
        static public void Save()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path          = Path.Combine(Directory.GetCurrentDirectory(), "data\\users.hav");
            string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "data");

            if (!File.Exists(path))
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                FileStream fs = File.Create(path);
                fs.Close();
            }
            UsertCollection usertCollection = new UsertCollection
            {
                Users = Items ?? new List <User>()
            };
            string   JSONString = JsonConvert.SerializeObject(usertCollection);
            FileRead JSONRead   = new FileRead();

            JSONRead.SaveJSONString(path, JSONString);
            Program.SelectUser = selUser;
        }
Ejemplo n.º 2
0
Archivo: user.cs Proyecto: groshik/curs
        static public void Load()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path = Path.Combine(Directory.GetCurrentDirectory(), "data\\users.hav");

            if (File.Exists(path))
            {
                string   JSONString;
                FileRead JSONRead = new FileRead();

                JSONString = JSONRead.GetJSONString(path);
                UsertCollection usertCollection = JsonConvert.DeserializeObject <UsertCollection>(JSONString);
                Items = usertCollection.Users;
                Items.ForEach(user =>
                {
                    user.ChangeDataEvent += () =>
                    {
                        ChangeDataInListEvent?.Invoke();
                    };
                });
            }
            else
            {
                Save();
                Load();
            }
            if (selUser != null)
            {
                selUser = Users.GetUser(selUser.Login);
            }
            Program.SelectUser = selUser;
        }