Beispiel #1
0
        private static void SaveScene(IRepositories repos, Scene scene, bool cloning)
        {
            throw new NotImplementedException();
            /*
            // enumerate scene's existing brick contents to track deleted ones
            var existingSceneWalls = repos.Scenes
                .Where(s => s.SceneId == scene.SceneId)
                .ToList() // because SelectMany() is not supported by MongoDB Linq yet
                .SelectMany(s => s.Walls);
            var existingBricks = existingSceneWalls
                .SelectMany(w => w.Bricks.Select(b => b.BrickContentId))
                .Where(id => !string.IsNullOrEmpty(id))
                .ToList();

            // TODO: it's good to implement some kind of version check on each scene
            // so that if designScene version is different from realScene version
            // we throw exception saying that somebody has already updated scene
            // while a user was editing it.

            foreach (var wall in scene.Walls)
            {
                foreach (var brick in wall.Bricks)
                {
                    if (cloning)
                    {
                        if (!string.IsNullOrEmpty(brick.BrickContentId)) // doesn't make sense to clone empty brick
                        {
                            var content = repos.BrickContents.First(c => c.BrickContentId == brick.BrickContentId);
                            content.BrickContentId = null;
                            repos.BrickContents.Insert(content);
                            brick.BrickContentId = content.BrickContentId;
                        }
                    }
                    else if (string.IsNullOrEmpty(brick.NewContentTypeName)) // existing brick
                    {
                        existingBricks.Remove(brick.BrickContentId);
                    }
                    else  // not empty brick
                    {
                        var contentType = MsCms.RegisteredBrickTypes
                            .Where(br => br.Type.Name == brick.NewContentTypeName)
                            .Select(br => br.Type)
                            .First();
                        var newContent = Activator.CreateInstance(contentType) as Brick;
                        repos.BrickContents.Insert(newContent);
                        brick.BrickContentId = newContent.BrickContentId;
                    }
                }
            }

            // save scene document
            repos.Scenes.Save(scene);

            // delete removed bricks
            existingBricks.ForEach(repos.BrickContents.Delete);
              * */
        }
 protected override void SaveScene(string templateId, Scene scene)
 {
     var holder = this.repos.SpecialScenes.FirstOrDefault(h => h.SceneId == templateId);
     if (holder == null)
     {
         holder = new SpecialScene();
     }
     holder.Scene = scene;
     this.repos.SpecialScenes.Save(holder);
 }
Beispiel #3
0
 public static void SaveScene(IRepositories repos, Scene scene)
 {
     SaveScene(repos, scene, false);
 }
 protected override void SaveScene(string communityId, Scene scene)
 {
     this.repos.Communities.Collection.Update(
         GetCommunityQuery(communityId),
         Update.Set("Scene", scene.ToBsonDocument()));
 }
 protected abstract void SaveScene(string entityId, Scene scene);
        public virtual ActionResult SaveScene(string id, string sceneJson)
        {
            var sceneHolder = GetSceneHolder(id);
            var converter = new SceneViewModelResolver(GetViewModelContext(sceneHolder));
            var scene = JsonConvert.DeserializeObject<SceneViewModel>(sceneJson, converter);
            if (ModelState.IsValid)
            {
                var originalSceneBricks = id.IsNullOrEmpty()
                    ? new Dictionary<string, Brick>()
                    : (sceneHolder.Scene ?? new Scene()).Walls
                        .SelectMany(w => w.Bricks)
                        .ToDictionary(b => b.BrickId, b => b);

                var sceneEntity = new Scene();
                var wallList = new List<Wall>();

                foreach (var wall in scene.Walls)
                {
                    var wallEntity = new Wall();
                    wallEntity.Title = wall.Title;
                    wallEntity.Width = wall.Width;

                    wallList.Add(wallEntity);

                    var brickList = new List<Brick>();

                    foreach (var brick in wall.Bricks)
                    {
                        Brick brickEntity = null;
                        if (!brick.BrickId.IsNullOrEmpty() && originalSceneBricks.ContainsKey(brick.BrickId))
                        {
                            brickEntity = originalSceneBricks[brick.BrickId];
                        }

                        if (brickEntity == null)
                        {
                            brickEntity = brick.Content;
                            brickEntity.BrickId = MongoDB.Bson.ObjectId.GenerateNewId().ToString();
                        }

                        brickEntity.Title = brick.Title;
                        brickEntity.Width = brick.Width;

                        brickList.Add(brickEntity);
                    }

                    wallEntity.Bricks = brickList;
                }

                sceneEntity.Walls = wallList;

                this.SaveScene(id, sceneEntity);
            }

            return RedirectToAction("EditScene", null, new { id });
        }
 protected override void SaveScene(string entityId, Scene scene)
 {
     var holder = this.repos.SpecialScenes.Single(h => h.SceneId == Constants.LinkableBricksSceneId);
     holder.Scene = scene;
     this.repos.SpecialScenes.Save(holder);
 }