Beispiel #1
0
        public async Task <ActionResult <FolderDTO> > GetFolder(Guid id)
        {
            FolderDTO folder = await _folderService.GetFolderById(id);

            if (folder == null)
            {
                return(NotFound());
            }

            if (!(await _authorizationService.AuthorizeAsync(
                      User, folder, Operations.Read)).Succeeded)
            {
                return(NotFound("Folder not found."));
            }
            if ((await _authorizationService.AuthorizeAsync(
                     User, folder, Operations.Create)).Succeeded)
            {
                folder.Links = _linkGenerator.GenerateAllLinks(User, folder);
            }
            else
            {
                folder.Links = _linkGenerator.GenerateRestrictedLinks(folder);
            }
            return(Ok(folder));
        }
Beispiel #2
0
        public async Task Post([FromBody] FolderDTO folder)
        {
            FolderEntity entity = FolderConverter.ToEntity(folder);

            this.context.Folders.Add(entity);
            await this.context.SaveChangesAsync();
        }
        public static List <FolderDTO> getAllFoldersList(int id)
        {
            List <FolderDTO> lst     = new List <FolderDTO>();
            String           sqlConn = @"Data Source=.\SQLEXPRESS2012; Initial Catalog=Assignment8; User id=sa; Password=120";

            using (SqlConnection conn = new SqlConnection(sqlConn))
            {
                conn.Open();
                String        query = String.Format(@"select * from dbo.Folder where ParentFolderId={0}", id);
                SqlCommand    comm  = new SqlCommand(query, conn);
                SqlDataReader rd    = comm.ExecuteReader();

                while (rd.Read() == true)
                {
                    FolderDTO obj = new FolderDTO();
                    obj.id             = rd.GetInt32(0);
                    obj.Name           = rd.GetString(1);
                    obj.ParentFolderId = rd.GetInt32(2);
                    obj.CreatedBy      = rd.GetInt32(3);
                    obj.CreatedOn      = rd.GetDateTime(4).ToString();
                    obj.IsActive       = rd.GetBoolean(5);

                    lst.Add(obj);
                }
            }
            return(lst);
        }
        public static int Save(FolderDTO dto)
        {
            String sqlConn = @"Data Source=.\SQLEXPRESS2012; Initial Catalog=Assignment8; User id=sa; Password=120";

            using (SqlConnection conn = new SqlConnection(sqlConn))
            {
                conn.Open();
                String sqlQuery = "";
                if (dto.id > 0)
                {
                    sqlQuery = String.Format("Update dbo.Folder Set Name='{0}',ParentFolderId={1} Where Id={2}",
                                             dto.Name, dto.ParentFolderId, dto.id);
                    SqlCommand comm = new SqlCommand(sqlQuery, conn);
                    comm.ExecuteNonQuery();

                    return(dto.id);
                }
                else
                {
                    sqlQuery = String.Format("INSERT INTO dbo.Folder(Name,ParentFolderId,CreatedBy, CreatedOn,IsActive) VALUES('{0}',{1},{2},'{3}',{4});",
                                             dto.Name, dto.ParentFolderId, dto.CreatedBy, dto.CreatedOn, 1);
                    SqlCommand comm = new SqlCommand(sqlQuery, conn);
                    comm.ExecuteNonQuery();

                    return(0);
                }
            }
        }
Beispiel #5
0
        public Task <FolderDTO> SearchAsync()
        {
            return(Task.Run(async() =>
            {
                var name = new DirectoryInfo(BaseDirectory).Name;
                var rootFolder = new FolderDTO(name, name, false, false, true);
                var directories = Directory.GetDirectories(BaseDirectory);
                var basePath = Path.GetDirectoryName(BaseDirectory);

                foreach (var directory in directories)
                {
                    var rel = MakeRelative(basePath, directory);
                    var subDirectoryInfo = new DirectoryInfo(directory);

                    var folder = new FolderDTO(subDirectoryInfo.Name, rel, true);
                    var subFolders = await GetFolder(basePath, subDirectoryInfo);
                    foreach (var subFolder in subFolders)
                    {
                        try
                        {
                            folder.SubFolders.Add(Path.Combine(rel, subFolder.Name), subFolder);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }

                    rootFolder.SubFolders.Add(Path.Combine(rel, folder.Name), folder);
                }

                return rootFolder;
            }));
        }
Beispiel #6
0
        private Task <List <FolderDTO> > GetFolder(string basePath, DirectoryInfo directoryInfo)
        {
            return(Task.Run(() =>
            {
                var directories = directoryInfo.GetDirectories();
                var result = new List <FolderDTO>();
                foreach (var directory in directories)
                {
                    var rel = MakeRelative(basePath, directory.FullName);
                    var folder = new FolderDTO(directory.Name, rel, false, true);
                    var files = GetFiles(directory, rel);

                    foreach (var file in files)
                    {
                        try
                        {
                            folder.Files.Add(file.FilePath, file);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Error: {ex.Message} - File: {file.FilePath}");
                        }
                    }

                    result.Add(folder);
                }

                return result;
            }));
        }
Beispiel #7
0
        public IHttpActionResult PostFolder(Folder folder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (folder.Name != null)
            {
                db.Folders.Add(folder);
                db.SaveChanges();

                // Load user name
                db.Entry(folder).Reference(X => X.User).Load();

                var DTO = new FolderDTO()
                {
                    Id       = folder.ID,
                    Name     = folder.Name,
                    UserName = folder.User.Email,
                    UserId   = folder.User.Id
                };

                return(CreatedAtRoute("DefaultApi", new { ID = folder.ID }, DTO));
            }
            else
            {
                return(Ok(folder));
            }
        }
        public async Task <FolderDTO> CreateAtRoot(FolderDTO folder, int userId)
        {
            folder.OwnerId    = userId;
            folder.LastChange = DateTime.Now;
            Folder createdFolder = await _uow.Folders.Create(_mapper.Map <Folder>(folder));

            return(_mapper.Map <FolderDTO>(createdFolder));
        }
Beispiel #9
0
        public static FolderEntity ToEntity(FolderDTO dto)
        {
            FolderEntity entity = new FolderEntity();

            entity.Name = dto.Name;

            return(entity);
        }
Beispiel #10
0
        public static FolderDTO ToDTO(FolderEntity entity)
        {
            FolderDTO dto = new FolderDTO();

            dto.Name = entity.Name;

            return(dto);
        }
Beispiel #11
0
 private static void PrintFolder(FolderDTO folder)
 {
     Console.WriteLine("Folder");
     Console.WriteLine($"Name: {folder.Name}");
     Console.WriteLine($"Id: {folder.Id}");
     Console.WriteLine($"Path: {folder.PathDisplay}");
     Console.WriteLine();
 }
        public int CreateFolder(FolderDTO folder)
        {
            int newId = unitOfWork.FolderRepository
                        .Add(mapper.Map <Folder>(folder));

            unitOfWork.Save();
            return(newId);
        }
 public async Task Update(FolderDTO folder)
 {
     if (folder == null)
     {
         throw new BadRequestException("Provided folder model is null.");
     }
     folder.LastChange = DateTime.Now;
     await _uow.Folders.Update(_mapper.Map <Folder>(folder));
 }
        public static int SaveFolder(string fname, int uid, int pid)
        {
            FolderDTO folder = new FolderDTO();

            folder.Name           = fname;
            folder.CreatedBy      = uid;
            folder.CreatedOn      = DateTime.Now;
            folder.ParentFolderId = pid;
            return(Drive.DAL.FolderDAO.SaveFolder(folder));
        }
Beispiel #15
0
        public Task <IdentityResult> DeleteUserAsync(int userId)
        {
            FolderDTO folder = mapper.Map <FolderDTO>(unitOfWork.FolderRepository.AllFolders
                                                      .FirstOrDefault(f => !f.FolderId.HasValue && f.UserId == userId));

            folderService.DeleteFolder(folder.Id);
            User user = userManager.Users.FirstOrDefault(u => u.Id == userId);

            return(userManager.DeleteAsync(user));
        }
Beispiel #16
0
        public static int Save(FolderDTO f)
        {
            String sqlQuery = sqlQuery = String.Format("INSERT INTO dbo.Folder(name,parentfolderid,createdon,isactive) VALUES('{0}',{1},'{2}',{3})",
                                                       f.folderName, f.parentFolderId, f.createdOn, 1);

            using (DBHelper helper = new DBHelper())
            {
                return(helper.ExecuteQuery(sqlQuery));
            }
        }
Beispiel #17
0
        public static Int32 SaveFolderInfo(FolderDTO dto)
        {
            var query = $"INSERT dbo.Folder(Name, ParentFolderID,CreatedOn,IsActive,OwnerID) " +
                        $"OUTPUT INSERTED.ID VALUES('{dto.Name}','{dto.ParentFolderID}','{dto.CreatedOn}','{dto.IsActive}', '{dto.OwnerID}')";

            using (var helper = new DBHelper())
            {
                return((int)helper.ExecuteScalar(query));
            }
        }
Beispiel #18
0
        private static FolderDTO FillDTO(SqlDataReader reader)
        {
            var dto = new FolderDTO();

            dto.ID             = reader.GetInt32(0);
            dto.Name           = reader.GetString(1);
            dto.ParentFolderID = reader.GetInt32(2);
            dto.CreatedOn      = reader.GetDateTime(3);
            dto.IsActive       = reader.GetBoolean(4);
            return(dto);
        }
Beispiel #19
0
        public ActionResult NormalUser()
        {
            @ViewBag.name   = Session["username"];
            @ViewBag.userid = Session["userid"];

            FolderBAL fb      = new FolderBAL();
            FolderDTO fd      = new FolderDTO();
            var       folders = fb.GetAllFolders();

            return(View(folders));
        }
Beispiel #20
0
 public void UpdateFolder(FolderDTO folder)
 {
     if (folder.Id != null)
     {
         Console.WriteLine("Folder Update");
     }
     else
     {
         Console.WriteLine("Folder New");
     }
 }
Beispiel #21
0
        public int CreateFolder()
        {
            FolderDTO dto = new FolderDTO();

            dto.Name           = HttpContext.Current.Request["foName"];
            dto.ParentFolderId = Convert.ToInt32(HttpContext.Current.Request["parentId"]);
            dto.CreatedBy      = Convert.ToInt32(HttpContext.Current.Request["createdBy"]);
            dto.CreatedOn      = DateTime.Now;
            dto.IsActive       = true;
            return(Drive.BAL.FolderBO.CreateFolder(dto));
        }
        /////////////////////////////////////////////////////////////////////
        private static FolderDTO FillDTO(SqlDataReader reader)
        {
            var dto = new FolderDTO();

            dto.id        = reader.GetInt32(reader.GetOrdinal("id"));
            dto.name      = reader.GetString(reader.GetOrdinal("Name"));
            dto.ParentId  = reader.GetInt32(reader.GetOrdinal("ParentFolderId"));
            dto.CreatedBy = reader.GetInt32(reader.GetOrdinal("CreatedBy"));
            dto.CreatedOn = reader.GetDateTime(reader.GetOrdinal("CreatedOn"));
            return(dto);
        }
        public IActionResult EditFolder(int id, [FromBody] FolderDTO folder)
        {
            var folderDto = _folderService.Get(id);

            if (folderDto.UserId != User.Identity.Name)
            {
                return(Forbid());
            }
            _folderService.EditFolder(id, folder);
            return(NoContent());
        }
Beispiel #24
0
        public async Task <ActionResult <FolderDTO> > Post([FromBody] FolderDTO folder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("The provided folder model is not valid."));
            }
            FolderDTO created = await _folderService.CreateAtRoot(folder,
                                                                  Convert.ToInt32(User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value));

            return(CreatedAtAction(nameof(Post), created));
        }
        public async Task MakeFolderUnshareable(FolderDTO folder)
        {
            Folder folderInDB = await _uow.Folders.GetFolderById(folder.Id);

            if (folderInDB == null)
            {
                throw new NotFoundException("The folder corresponding to the model does not exist");
            }

            await UnShareFolderSubfolders(folder.Id);
        }
Beispiel #26
0
        private static FolderDTO FillDTO(SqlDataReader reader)
        {
            var dto = new FolderDTO();

            dto.folderId       = reader.GetInt32(0);
            dto.folderName     = reader.GetString(1);
            dto.parentFolderId = reader.GetInt32(2);
            dto.createdOn      = reader.GetDateTime(3).ToString("yyyy-MM-dd hh:mm:ss");
            dto.IsActive       = reader.GetBoolean(4);
            return(dto);
        }
        //Ok
        public FolderDTO CreateRootFolder(string userId, string email)
        {
            FolderDTO folder = new FolderDTO()
            {
                Name   = email,
                Path   = "",
                UserId = email,
            };

            Create(folder);
            return(folder);
        }
        public IActionResult CreateFolder(FolderViewModel folder)
        {
            Guid      userGuid  = Guid.Parse(HttpContext.User.Identity.GetUserId());
            FolderDTO folderDTO = new FolderDTO
            {
                Name     = folder.Name,
                ParentId = folder.ParentId
            };

            folderDTO = _folderService.CreateFolder(folderDTO, userGuid);
            return(Json(folderDTO));
        }
Beispiel #29
0
        public static List <FolderDTO> GetNavigationByFolderIdAndUserId(int FolderId, int UserId)
        {
            List <FolderDTO> path      = new List <FolderDTO>();
            FolderDTO        folderDTO = null;

            while ((folderDTO = FolderDAL.GetFolderByFolderIdAndUserId(FolderId, UserId)) != null)
            {
                FolderId = folderDTO.ParentFolderId;
                path.Add(folderDTO);
            }
            return(path);
        }
Beispiel #30
0
        public void AddFolder(FolderDTO folderDTO)
        {
            Folder folder = new Folder()
            {
                Id        = Guid.NewGuid().ToString(),
                AppUserId = folderDTO.AppUserId,
                Title     = folderDTO.Title,
                ParentId  = folderDTO.ParentId
            };

            Unit.Folders.Add(folder);
            Unit.Save();
        }