mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
49 lines
1.3 KiB
C#
49 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Web.Script.Serialization;
|
|
using AppleBatch_June.Model;
|
|
|
|
namespace AppleBatch_June.Domain
|
|
{
|
|
public class UserNationalData
|
|
{
|
|
private string path => AppDomain.CurrentDomain.BaseDirectory;
|
|
|
|
private string mvationPath => path + "userNationalData.json";
|
|
|
|
public List<NationalList> getMation()
|
|
{
|
|
if (File.Exists(mvationPath))
|
|
{
|
|
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
|
|
string input = Tools.readFile(mvationPath, Encoding.UTF8);
|
|
return javaScriptSerializer.Deserialize<List<NationalList>>(input);
|
|
}
|
|
return new List<NationalList>();
|
|
}
|
|
|
|
public void saveMation(NationalList item)
|
|
{
|
|
List<NationalList> mation = getMation();
|
|
mation.Add(item);
|
|
string contents = new JavaScriptSerializer().Serialize(mation);
|
|
File.WriteAllText(mvationPath, contents, Encoding.UTF8);
|
|
}
|
|
|
|
public void removeMation(string code)
|
|
{
|
|
List<NationalList> mation = getMation();
|
|
NationalList nationalList = mation.Where((NationalList c) => c.Id == code).FirstOrDefault();
|
|
if (nationalList != null)
|
|
{
|
|
mation.Remove(nationalList);
|
|
string contents = new JavaScriptSerializer().Serialize(mation);
|
|
File.WriteAllText(mvationPath, contents, Encoding.UTF8);
|
|
}
|
|
}
|
|
}
|
|
}
|