Exemple #1
0
        public ActionResult CreateMap(SaveMapViewModel newMapModel)
        {
            if (ModelState.IsValid)
            {
                var      id  = User.Identity.GetUserId();
                ObjectId oId = new ObjectId(id);

                MapPermissions mapPermissions = new MapPermissions();
                mapPermissions.Owner    = new KeyValuePair <ObjectId, MapPermissionType>(oId, MapPermissionType.RW);
                mapPermissions.Users    = new Dictionary <ObjectId, MapPermissionType>();
                mapPermissions.Groups   = new Dictionary <ObjectId, MapPermissionType>();
                mapPermissions.AllUsers = MapPermissionType.NA;

                mapPermissions.Users.Add(oId, MapPermissionType.RW);

                BsonDocument bMapModel = BsonDocument.Parse(newMapModel.Model);
                //BsonDocument bMapModel = mapModel.ToBsonDocument();


                Queue <MapVersion> versions = new Queue <MapVersion>(MapVersion.VERSIONS);
                versions.Enqueue(new MapVersion {
                    CreationTime = DateTime.Now, Model = bMapModel
                });

                Map map = new Map {
                    Name = newMapModel.Name, Creator = oId, CreationTime = DateTime.Now, Description = newMapModel.Description, Model = bMapModel, Permissions = mapPermissions, MapsArchive = versions, Followers = new HashSet <ObjectId>()
                };
                var mId = _mapManager.AddMap(map);

                ObjectId  mapID = new ObjectId(mId);
                string    currentFolderIdString = _currentFolderID;
                ObjectId  folderID = new ObjectId(currentFolderIdString);
                MapFolder folder   = _folderManeger.GetMapFolderById(folderID);

                string path = folder.Model["path"].ToString();
                if (path.Equals(""))
                {
                    path = folder.Name;
                }
                else
                {
                    path = path + "/" + folder.Name;
                }
                bMapModel.Add("path", path);
                map.Model = bMapModel;
                _mapManager.UpdateMap(map);


                folder.idOfMapsInFolder.Add(mapID);
                _folderManeger.UpdateMapFolder(folder);

                return(Json(new { mapId = mId, mapName = map.Name }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { success = false }));
        }
 public bool AddUserToFolder(string uId, string folderId, MapPermissionType per)
 {
     if (IsOwner(folderId) && _userService.IsUserlExist(new ObjectId(uId)))
     {
         var folder = _folderManeger.GetMapFolderById(new ObjectId(folderId));
         if (folder != null && folder.Creator.ToString() != uId)
         {
             folder.Permissions.Users[new ObjectId(uId)] = per;
             _folderManeger.UpdateMapFolder(folder);
             return(true);
         }
     }
     return(false);
 }
        public void deleteFolder(string currFolder)
        {
            MapFolderDB folderManeger = new MapFolderDB(new Settings());
            ObjectId    currFolderID  = new ObjectId(currFolder);
            MapFolder   currentFolder = folderManeger.GetMapFolderById(currFolderID);

            try
            {
                foreach (ObjectId idOfSubFolder in currentFolder.idOfSubFolders)
                {
                    deleteFolder(idOfSubFolder.ToString());
                }
            }
            catch
            {
            }
            ObjectId  prevFolderID = currentFolder.ParentDierctory;
            MapFolder prevFolder   = folderManeger.GetMapFolderById(prevFolderID);

            foreach (ObjectId objID in prevFolder.idOfSubFolders)
            {
                if (currFolderID.Equals(objID))
                {
                    currFolderID = objID;
                }
            }
            prevFolder.idOfSubFolders.Remove(currFolderID);
            folderManeger.UpdateMapFolder(prevFolder);
            folderManeger.RemoveMapFolderById(currFolderID);
            ViewBag.go2 = prevFolderID.ToString();
        }
        public void MoveFolderToFolder(string folderToMoveId, string moveToFolderId)
        {
            if (!folderToMoveId.Equals(moveToFolderId))
            {
                MapFolder folderToMove  = _mapFolderDataManager.GetMapFolderById(new ObjectId(folderToMoveId));
                MapFolder moveToFolder  = _mapFolderDataManager.GetMapFolderById(new ObjectId(moveToFolderId));
                MapFolder oldPrevFolder = _mapFolderDataManager.GetMapFolderById(folderToMove.ParentDierctory);
                if (!moveToFolder.Id.Equals(oldPrevFolder.Id))
                {
                    oldPrevFolder.idOfSubFolders.Remove(folderToMove.Id);
                    folderToMove.ParentDierctory = moveToFolder.Id;
                    moveToFolder.idOfSubFolders.Add(folderToMove.Id);

                    _mapFolderDataManager.UpdateMapFolder(folderToMove);
                    _mapFolderDataManager.UpdateMapFolder(moveToFolder);
                    _mapFolderDataManager.UpdateMapFolder(oldPrevFolder);
                }
            }
        }