public DoctrinaScript CreateScript(CreateScriptViewModel model)
        {
            DoctrinaScript newScript = new DoctrinaScript
            {
                Title                = model.Title,
                Creator              = model.Creator,
                DateCreated          = model.DateCreated,
                DoctrinaGroupSection = GetSection(model.SectionId)
            };

            _db.Add <DoctrinaScript>(newScript);
            _db.SaveChanges();

            DoctrinaScript result = _db.DoctrinaScripts
                                    .Where(s => s.Creator == model.Creator && s.DateCreated == model.DateCreated && s.Title == model.Title)
                                    .FirstOrDefault();

            // WebRootPath is server-side path for displaying the file into the iframe
            string webRootPath = $"~/DynamicResources/groups/{model.GroupId}/{model.SectionId}/{result.Id}.html";
            // AbsolutePath is full path used for CRUD operations with file
            string absolutePath = Path.Combine(_hostingEnvironment.WebRootPath, $"DynamicResources/groups/{model.GroupId}/{model.SectionId}/{result.Id}.html");

            File.Create(absolutePath);

            result.WebRootPath  = webRootPath;
            result.AbsolutePath = absolutePath;

            _db.DoctrinaScripts.Attach(result);
            _db.Entry(result).State = EntityState.Modified;
            _db.SaveChanges();

            return(result);
        }
        public void DeleteScript(string id)
        {
            DoctrinaScript script = _db.Find <DoctrinaScript>(id);

            File.SetAttributes(script.AbsolutePath, FileAttributes.Normal);
            File.Delete(script.AbsolutePath);

            _db.Remove <DoctrinaScript>(script);
            _db.SaveChanges();
        }
        public DoctrinaScript GetScript(string id)
        {
            DoctrinaScript result = _db.DoctrinaScripts.Where(s => s.Id == id).FirstOrDefault();

            return(result);
        }