예제 #1
0
 public FolderDetailsDto GetFolderDetails(string securityToken, long?idFolder)
 {
     try
     {
         var session             = CheckSession(securityToken);
         FolderDetailsDto result = new FolderDetailsDto();
         if (idFolder.HasValue)
         {
             result = Mapper.Map <FolderDetailsDto>(_dao.ReadFullFolder(idFolder.Value));
         }
         else
         {
             result.Folders = Mapper.Map <List <FolderDto> >(_dao.GetFoldersInRoot(session.IdUser));
             using (var fileService = new FileServices())
             {
                 result.Files = fileService.GetFilesInRoot(securityToken);
             }
         }
         return(result);
     }
     catch (FileSharingException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
     }
 }
예제 #2
0
        public void Delete(string securityToken, string password)
        {
            try
            {
                var session = CheckSession(securityToken);
                var user    = _dao.Read(session.IdUser);
                if (user.Password != EncryptPassword(password))
                {
                    throw new FileSharingException(FileSharingException.INVALID_CREDENTIALS,
                                                   "The password is invalid");
                }

                using (var groupServices = new GroupServices())
                {
                    var groups = groupServices.GetAdministrableGroups(securityToken);
                    if (groups != null && groups.Count > 0)
                    {
                        throw new FileSharingException(FileSharingException.USER_CANNOT_BE_REMOVED,
                                                       "The user cannot be removed because he is group admin");
                    }
                }

                using (var fileService = new FileServices())
                {
                    foreach (var doc in user.Files)
                    {
                        fileService.Delete(securityToken, doc.Id);
                    }
                }

                using (var folderServices = new FolderServices())
                {
                    foreach (var folder in user.Folders)
                    {
                        folderServices.Delete(securityToken, folder.Id);
                    }
                }

                _dao.Delete(user);

                Audit(user.Id, user.Id.ToString(), typeof(User).Name, ActionDto.Delete, "User deleted: " + user);
            }
            catch (Exception e)
            {
                throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
            }
        }