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 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); }