public static bool Exists(string filename) { using (JsonStoreDataContext db = new JsonStoreDataContext()) { return((from pp in db.tbl_JsonFiles where pp.Name.Equals(filename) select pp).Count() > 0); } }
public static bool Add(ref JsonFile file) { if (!file.Name.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase)) { file.Name = file.Name + ".json"; } if (Exists(file.Name)) { return(false); } if (!string.IsNullOrEmpty(file.Contents)) { file.Path = getRelativeFilePath(encodeFileName(file.Name)); file.Contents.SaveToFile(Site.MapPath(file.Path)); } file.CreationTime = DateTime.Now; file.LastUpdateTime = DateTime.Now; using (JsonStoreDataContext context = new JsonStoreDataContext()) { context.tbl_JsonFiles.InsertOnSubmit(Map(file)); context.SubmitChanges(); } file.ID = GetJsonFile(0L, file.Name).ID; return(true); }
public static JsonFile GetJsonFile(long id = 0, string filename = "") { JsonFile file = new JsonFile(); using (JsonStoreDataContext db = new JsonStoreDataContext()) { return((new JsonFile()).Map((from pp in db.tbl_JsonFiles where id.Equals(0) || pp.ID.Equals(id) select pp).FirstOrDefault())); } }
public static JsonFile UpdateJsonFile(long id = 0L, string filename = "") { JsonFile file = new JsonFile(); using (JsonStoreDataContext db = new JsonStoreDataContext()) { tbl_JsonFile jfile = (from pp in db.tbl_JsonFiles where id.Equals(0) || pp.ID.Equals(id) select pp).FirstOrDefault(); jfile.LastUpdateTime = DateTime.Now; file = file.Map(jfile); db.SubmitChanges(); } return(file); }
public static List <JsonFile> GetJsonFiles(long backupOf = 0L) { List <JsonFile> list = new List <JsonFile>(); using (JsonStoreDataContext db = new JsonStoreDataContext()) { foreach (var result in (from pp in db.tbl_JsonFiles where ((backupOf.Equals(0)) || pp.BackupOf.Equals(backupOf)) select pp).ToList()) { list.Add((new JsonFile()).Map(result)); } } return(list); }