public static EditorModelData GetProjectEditorData(FrontEditorContext _context, int projectId) { ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (data == null) { data = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(new EditorModelData()) }; _context.Add(data); _context.SaveChanges(); } return(parser.DeserializeData(data.ProjectData)); }
public static void ImportProjectFromZip(FrontEditorContext _context, int projectId, string rootPath, string zipPath) { try { string tempPath = rootPath + "/import/" + projectId + "-import-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "/"; string imagesPath = rootPath + "/images/projects/" + projectId + "/"; ZipFile.ExtractToDirectory(zipPath, tempPath); //Parse json and Save it string importedData = System.IO.File.ReadAllText(tempPath + "project.json"); EditorModelData data = parser.DeserializeData(importedData); ProjectJSON jsonData = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (jsonData == null) { jsonData = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(data) }; _context.Add(jsonData); } else { jsonData.ProjectData = parser.SerializeData(data); _context.Update(jsonData); } _context.SaveChanges(); //Empty files folder and copy new files to files folder foreach (string file in Directory.GetFiles(imagesPath, "*.*", SearchOption.AllDirectories)) { File.Delete(file); } foreach (string file in Directory.GetFiles(tempPath + "images/", "*.*", SearchOption.AllDirectories)) { File.Copy(file, file.Replace(imagesPath, tempPath), true); } //Delete import files from temp folder Directory.Delete(tempPath, true); } catch (Exception ex) { throw new Exception("Hiba történta projekt impotálása közben!"); } }
public static void SaveProjectEditorData(FrontEditorContext _context, int projectId, EditorModelData saveData) { ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault(); if (data == null) { data = new ProjectJSON() { ProjectId = projectId, ProjectData = parser.SerializeData(saveData) }; _context.Add(data); } else { data.ProjectData = parser.SerializeData(saveData); _context.Update(data); } _context.SaveChanges(); }