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 AddUserToMap(string uId, string mapId, MapPermissionType per) { if (IsOwner(mapId) && _userService.IsUserlExist(new ObjectId(uId))) { var map = _mapManager.GetMapById(new ObjectId(mapId)); if (map != null && map.Creator.ToString() != uId) { map.Permissions.Users[new ObjectId(uId)] = per; _mapManager.UpdateMap(map); return(true); } } return(false); }
public void MoveMapToFolder(string mapToMoveId, string moveToFolderId) { Map mapToMove = _mapDataManager.GetMapById(new ObjectId(mapToMoveId)); MapFolder moveToFolder = _mapFolderDataManager.GetMapFolderById(new ObjectId(moveToFolderId)); MapFolder oldPrevFolder = null; string userIdAsString = User.Identity.GetUserId(); ObjectId userObjectID = new ObjectId(userIdAsString); var allFoldersOfUser = _mapFolderDataManager.GetAllMapFoldersOfUser(userObjectID); var allFolderOwnedByUsr = new List <MapFolder>(); foreach (var folder in allFoldersOfUser) { if (folder.Permissions.Owner.Key.ToString().Equals(userObjectID.ToString()) && !folder.Model["type"].Equals(SharedCodedData.SHARED_SUPIRIOR)) { if (folder.idOfMapsInFolder.Contains(mapToMove.Id)) { oldPrevFolder = folder; break; } } } if (oldPrevFolder.Id.Equals(moveToFolder.Id)) { return; } oldPrevFolder.idOfMapsInFolder.Remove(mapToMove.Id); moveToFolder.idOfMapsInFolder.Add(mapToMove.Id); _mapDataManager.UpdateMap(mapToMove); _mapFolderDataManager.UpdateMapFolder(moveToFolder); _mapFolderDataManager.UpdateMapFolder(oldPrevFolder); }