Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
        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()));
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }