Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("Id,ParentDirId,Name")] FunDir funDir)
        {
            if (ModelState.IsValid)
            {
                var _FunDirNameLength = funDir?.Name?.Length ?? 0;

                if (_FunDirNameLength < 1 || _FunDirNameLength > 100)
                {
                    ModelState.AddModelError(
                        nameof(funDir.Name),
                        _localizer["The length of directory name must be less than 100 and more than 1"]);

                    return(View());
                }

                var User_ = await _userManager.GetUserAsync(User);

                funDir.Id         = Guid.NewGuid();
                funDir.DOCreating = DateTimeOffset.Now;
                funDir.UserId     = User_.Id;

                _context.Add(funDir);
                await _context.SaveChangesAsync();

                return(RedirectToAction(
                           nameof(Index),
                           new{ funDir.ParentDirId }
                           ));
            }
            return(View(funDir));
        }
Exemplo n.º 2
0
        // GET: FunFiles/FunDirs/Create
        public IActionResult Create(Guid?ParentDirId)
        {
            var _FunDir = new FunDir
            {
                ParentDirId = ParentDirId ?? _funFilesHelper.RootDirId
            };

            return(View(_FunDir));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name")] FunDir funDir)
        {
            if (id != funDir.Id)
            {
                return(NotFound());
            }

            var ParentDirId = Guid.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    var UserId_ = _userManager.GetUserAsync(User).GetAwaiter().GetResult().Id;

                    var _FunDir = await _context.FunDir.Where(p => p.Id == funDir.Id && p.UserId == UserId_).FirstOrDefaultAsync();

                    if (_FunDir != null)
                    {
                        _FunDir.Name = funDir.Name;
                    }

                    await _context.SaveChangesAsync();

                    ParentDirId = _FunDir.ParentDirId;
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FunDirExists(funDir.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new{ ParentDirId }));
            }
            return(View(funDir));
        }
Exemplo n.º 4
0
        private async Task <bool> CopyDir(
            Guid ParentDirId,
            IdentityUser User_,
            List <FunDir> _FunDirs,
            List <FunYourFile> _FunYourFiles,
            FunDir TargetFunDir
            )
        {
            var _NewFunYourFiles = new List <FunYourFile>();

            var _NewFunDirs = new List <FunDir>();

            var _FunNewIds = new List <FunNewId>()
            {
                new FunNewId {
                    Id    = TargetFunDir.Id,
                    NewId = Guid.NewGuid()
                }
            };


            var IdAndParentIds = _FunDirs
                                 .Select(
                p =>
                new IdAndParentId
            {
                Id       = p.Id,
                ParentId = p.ParentDirId
            }
                )
                                 .Union(
                _FunYourFiles
                .Select(
                    p =>
                    new IdAndParentId
            {
                Id       = p.Id,
                ParentId = p.ParentDirId
            }
                    )
                )
                                 .ToList();


            _FunDirs.Select(p => p.Id)
            .Union(
                _FunYourFiles
                .Select(p => p.Id))
            .ToList()
            .ForEach(
                p =>
            {
                if (_funFilesHelper.IsIdInParentDirId(TargetFunDir.Id, p, IdAndParentIds))
                {
                    _FunNewIds.Add(
                        new FunNewId
                    {
                        Id    = p,
                        NewId = Guid.NewGuid()
                    }
                        );
                }
            }
                );

            _FunNewIds.ForEach(
                p =>
            {
                var _ParentDirId_ = _FunNewIds
                                    .Where(
                    n =>
                    n.Id == IdAndParentIds
                    .Where(i => i.Id == p.Id)
                    .Select(i => i.ParentId).FirstOrDefault()
                    ).Select(o => o.NewId).FirstOrDefault();

                _ParentDirId_ = _ParentDirId_ == Guid.Empty ? ParentDirId : _ParentDirId_;

                // is file
                if (_FunYourFiles.Any(f => f.Id == p.Id))
                {
                    var _FunYourFile_ = _FunYourFiles.Where(f => f.Id == p.Id).FirstOrDefault();
                    _NewFunYourFiles.Add(
                        new FunYourFile
                    {
                        DOUploading = DateTimeOffset.Now,
                        FileByteId  = _FunYourFile_.FileByteId,
                        Id          = p.NewId,
                        Name        = _FunYourFile_.Name,
                        ParentDirId = _ParentDirId_,
                        UserId      = User_.Id
                    }
                        );
                }
                // is directory
                else
                {
                    var _FunDir_ = _FunDirs.Where(d => d.Id == p.Id).FirstOrDefault();
                    _NewFunDirs.Add(
                        new FunDir
                    {
                        DOCreating  = DateTimeOffset.Now,
                        Id          = p.NewId,
                        Name        = _FunDir_.Name,
                        ParentDirId = _ParentDirId_,
                        UserId      = User_.Id
                    }
                        );
                }
            }
                );

            try{
                if (_NewFunDirs.Count() > 0)
                {
                    await _context.FunDir.AddRangeAsync(_NewFunDirs);
                }

                if (_NewFunYourFiles.Count() > 0)
                {
                    await _context.FunYourFile.AddRangeAsync(_NewFunYourFiles);
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }


            return(true);
        }