Esempio n. 1
0
        public Success ChangeFolderData(User user, ChangeFolderData originalFolder, string newName, AccessType?newAccess)
        {
            Folder folder = context.Folders
                            .FirstOrDefault(item => item.Owner == user &&
                                            item.FolderName == originalFolder.Name &&
                                            item.Access == originalFolder.Access);

            if (folder != null)
            {
                if (context.Folders.Where(a => a.Owner == user && a.FolderName == newName).SingleOrDefault() == null)
                {
                    if (newName != null)
                    {
                        folder.FolderName = newName;
                    }
                    if (newAccess != null)
                    {
                        folder.Access = (AccessType)newAccess;
                    }
                    ;
                    context.SaveChanges();
                    return(Success.Successfull);
                }
                ;
                return(Success.FailedByUsedName);
            }
            return(Success.FailedByNotExist);
        }
Esempio n. 2
0
        public IActionResult CreateNewFolder([FromBody] ChangeFolderData folder)
        {
            if (userGet.HaveUser(HttpContext))
            {
                if (folder.Access != null && folder.Name != null)
                {
                    Folder  newFolder = new Folder(folder.Name, (AccessType)folder.Access, userGet.GetUser(HttpContext));
                    Success success   = folderRepository.SaveNewFolder(newFolder);
                    switch (success)
                    {
                    case Success.Successfull:
                        return(Ok());

                    case Success.FailedByUsedName:
                        return(BadRequest("Foldername already used!"));
                    }
                }
                return(BadRequest("Not valid AccessType, or FolderName!"));
            }
            return(Unauthorized());
        }
Esempio n. 3
0
        public IActionResult ChangeFolderName(ChangeFolderData changeFolderData)
        {
            if (userGet.HaveUser(HttpContext))
            {
                Success success = folderRepository.ChangeFolderData(
                    userGet.GetUser(HttpContext),
                    changeFolderData.originalFolder,
                    changeFolderData.Name,
                    changeFolderData.Access);
                switch (success)
                {
                case Success.Successfull:
                    return(Ok());

                case Success.FailedByNotExist:
                    return(BadRequest("Folder doesn't exist!"));

                case Success.FailedByUsedName:
                    return(BadRequest("Foldername already used!"));
                }
            }
            return(Unauthorized());
        }