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();
        }
        // GET: MapFolder
        public ActionResult Index(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var Folderid = new ObjectId(id);
                var Folder   = _mapFolderDataManager.GetMapFolderById(Folderid);
                if (Folder != null)
                {
                    var  userId      = User.Identity.GetUserId();
                    bool isFollowing = Folder.Followers.Contains(new ObjectId(userId), new IDComparer());
                    ViewBag.isFollowing = isFollowing;
                    MapPermissionController mpc = new MapPermissionController();
                    // MapViewModel mvm = new MapViewModel { Id = map.Id, Name = map.Name, CreationTime = map.CreationTime, CreatorId = map.Creator, CreatorEmail = UserManager.GetEmail(map.Creator.ToString()), Description = map.Description, Model = map.Model, ModelArchive = map.MapsArchive };

                    if (Folder.Permissions.Owner.Key.ToString().Equals(userId))
                    {
                        return(View());
                    }
                    else
                    {
                        return(View());
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Details(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                MapFolderDB _mfManeger   = new MapFolderDB(new Settings());
                UserDB      _userManeger = new UserDB(new Settings());

                var mId    = new ObjectId(id);
                var folder = _mfManeger.GetMapFolderById(mId);
                if (folder != null)
                {
                    var  userId      = User.Identity.GetUserId();
                    bool isFollowing = folder.Followers.Contains(new ObjectId(userId), new IDComparer());
                    ViewBag.isFollowing = isFollowing;
                    FolderPermissionController fpc = new FolderPermissionController();
                    MapViewModel mvm = new MapViewModel {
                        Id = folder.Id, Name = folder.Name, CreationTime = folder.CreationTime, CreatorId = folder.Creator, CreatorEmail = "not supported yet" /*UserManager.GetEmail(map.Creator.ToString())*/, Description = folder.Description, Model = folder.Model, ModelArchive = null
                    };
                    if (fpc.IsFolderOwner(id, User.Identity.GetUserId()))
                    {
                        return(View(mvm));
                    }
                    else
                    {
                        return(View(mvm));
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
        public void addNewFolder(string parentID, string folderName, string folderDescription)
        {
            MapFolderDB folderManeger = new MapFolderDB(new Settings());
            var         id            = User.Identity.GetUserId();
            ObjectId    UserId        = new ObjectId(id);

            if (parentID == null || parentID.Equals(""))
            {
                parentID = folderManeger.GetSuperiorMapFolderOfUser(UserId).Id.ToString();
            }
            _mapFolderDataManager = new MapFolderDB(new Settings());


            MapPermissions mapPermissions = new MapPermissions();

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

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

            MapFolder folder = new MapFolder();

            folder.Name             = folderName;
            folder.Creator          = UserId;
            folder.CreationTime     = DateTime.Now;
            folder.Description      = folderDescription;
            folder.Followers        = new HashSet <ObjectId>();
            folder.Permissions      = mapPermissions;
            folder.idOfMapsInFolder = new HashSet <ObjectId>();
            folder.idOfSubFolders   = new HashSet <ObjectId>();
            folder.ParentDierctory  = new ObjectId(parentID);
            MapFolder parentFolder = folderManeger.GetMapFolderById(folder.ParentDierctory);
            string    path         = parentFolder.Model["path"].ToString();

            if (path.Equals(""))
            {
                path = parentFolder.Name;
            }
            else
            {
                path = path + "/" + parentFolder.Name;
            }
            if ((parentFolder.Model["type"]).Equals("sharedSup") || (parentFolder.Model["type"]).Equals("shared"))
            {
                folder.Model = new BsonDocument {
                    { "type", NOT_SUPIRIOR_BUT_SHARED }, { "path", path }
                };
            }
            else
            {
                folder.Model = new BsonDocument {
                    { "type", NOT_SUPIRIOR_BUT_OWNED }, { "path", path }
                };
            }

            folderManeger.AddSubFolder(parentFolder, folder);
        }
Exemple #5
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 }));
        }
Exemple #6
0
        public ActionResult Index(string id, string ownedOrShared)
        {
            //MailSender.SendMailMessage("*****@*****.**", "*****@*****.**", "", "", "(do not reply)", "lalalalalala");
            bool isOwned;
            bool isShared;

            ViewBag.isShared = ownedOrShared != null && ownedOrShared.Equals("shared");
            if (ownedOrShared == null)
            {
                isOwned  = false;
                isShared = false;
            }
            else
            {
                isOwned  = ownedOrShared.Equals("owned");
                isShared = ownedOrShared.Equals("shared");
            }
            ViewBag.ownedFolderID = null;
            MapFolderDB mapFolderManeger = new MapFolderDB(new Settings());
            bool        isIdOfOwned      = false;

            if (id != null)
            {
                ObjectId  oId = new ObjectId(id);
                MapFolder mf  = mapFolderManeger.GetMapFolderById(oId);
                if (isOwned)
                {
                    ViewBag.ownedFolderID = oId;
                    isIdOfOwned           = true;
                }
            }
            if (!isIdOfOwned)
            {
                ObjectId userID    = new ObjectId(User.Identity.GetUserId());
                var      supFolder = new MapFolderDB(new Settings()).GetSuperiorMapFolderOfUserOwned(userID);
                if (supFolder != null)
                {
                    ObjectId fId = supFolder.Id;
                    ViewBag.ownedFolderID = fId;
                }
                else
                {
                    supFolder = createSuppFolderLocaly(SharedCodedData.OWNED_SUPIRIOR);
                    mapFolderManeger.AddFolder(supFolder);
                    ObjectId fId = supFolder.Id;
                    ViewBag.ownedFolderID = fId;
                }
            }

            ViewBag.sharedFolderID = null;

            bool isIdOfShared = false;

            if (id != null)
            {
                ObjectId  oId = new ObjectId(id);
                MapFolder mf  = mapFolderManeger.GetMapFolderById(oId);
                if (isShared)
                {
                    ViewBag.sharedFolderID = oId;
                    isIdOfShared           = true;
                }
            }
            if (!isIdOfShared)
            {
                ObjectId userID    = new ObjectId(User.Identity.GetUserId());
                var      supFolder = new MapFolderDB(new Settings()).GetSuperiorMapFolderOfUserShared(userID);
                if (supFolder != null)
                {
                    ObjectId fId = supFolder.Id;
                    ViewBag.sharedFolderID = fId;
                }
                else
                {
                    supFolder = createSuppFolderLocaly(SharedCodedData.SHARED_SUPIRIOR);
                    mapFolderManeger.AddFolder(supFolder);
                    ObjectId fId = supFolder.Id;
                    ViewBag.sharedFolderID = fId;
                }
            }

            return(View());
        }
        public Dictionary <ApplicationUser, MapPermissionType> GetUsersPermissions(string folderId)
        {
            var folder = _folderManeger.GetMapFolderById(new ObjectId(folderId));
            Dictionary <ApplicationUser, MapPermissionType> users = new Dictionary <ApplicationUser, MapPermissionType>();

            foreach (var item in folder.Permissions.Users)
            {
                var user = UserManager.FindById(item.Key.ToString());
                users.Add(user, item.Value);
            }
            return(users);
        }