Пример #1
0
        public async Task <JsonResult> EditBucket([FromForm] EditBucketAddressModel model)
        {
            var app = await ApiService.ValidateAccessTokenAsync(model.AccessToken);

            var existing = _dbContext.Bucket.Exists(t => t.BucketName == model.NewBucketName && t.BucketId != model.BucketId);

            if (existing)
            {
                return(this.Protocal(ErrorType.NotEnoughResources, "There is one bucket already called that name!"));
            }
            var target = await _dbContext.Bucket.FindAsync(model.BucketId);

            if (target == null)
            {
                return(this.Protocal(ErrorType.NotFound, "Not found target bucket!"));
            }
            else if (target.BelongingAppId != app.AppId)
            {
                return(this.Protocal(ErrorType.Unauthorized, "This is not your bucket!"));
            }
            var oldpath = _configuration["StoragePath"] + $@"{_}Storage{_}{target.BucketName}";
            var newpath = _configuration["StoragePath"] + $@"{_}Storage{_}{model.NewBucketName}";

            if (oldpath != newpath)
            {
                new DirectoryInfo(oldpath).MoveTo(newpath);
            }
            target.BucketName   = model.NewBucketName;
            target.OpenToRead   = model.OpenToRead;
            target.OpenToUpload = model.OpenToUpload;
            await _dbContext.SaveChangesAsync();

            return(this.Protocal(ErrorType.Success, "Successfully edited your bucket!"));
        }
Пример #2
0
        public async Task <JsonResult> EditBucket([FromForm] EditBucketAddressModel model)
        {
            var app = await APIService.ValidateAccessTokenAsync(model.AccessToken);

            var existing = await _dbContext.Bucket.SingleOrDefaultAsync(t => t.BucketName == model.NewBucketName && t.BucketId != model.BucketId);

            if (existing != null)
            {
                return(Json(new AiurProtocal
                {
                    code = ErrorType.NotEnoughResources,
                    message = "There is one bucket already called that name!"
                }));
            }
            var target = await _dbContext.Bucket.FindAsync(model.BucketId);

            if (target == null)
            {
                return(Json(new AiurProtocal {
                    code = ErrorType.NotFound, message = "Not found bucket!"
                }));
            }
            else if (target.BelongingAppId != app.AppId)
            {
                return(Json(new AiurProtocal {
                    code = ErrorType.Unauthorized, message = "Not your bucket!"
                }));
            }
            var oldpath = GetCurrentDirectory() + $@"{_}Storage{_}{target.BucketName}";
            var newpath = GetCurrentDirectory() + $@"{_}Storage{_}{model.NewBucketName}";

            if (oldpath != newpath)
            {
                new DirectoryInfo(oldpath).MoveTo(newpath);
            }
            target.BucketName   = model.NewBucketName;
            target.OpenToRead   = model.OpenToRead;
            target.OpenToUpload = model.OpenToUpload;
            await _dbContext.SaveChangesAsync();

            return(Json(new AiurProtocal {
                code = ErrorType.Success, message = "Successfully edited your bucket!"
            }));
        }