Ejemplo n.º 1
0
        public async Task <IActionResult> RenameFile(RenameFileViewModel model)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(model.AppId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            if (!ModelState.IsValid)
            {
                model.Recover(user, app.AppName);
                return(View(model));
            }
            try
            {
                var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret);

                await _filesService.RenameFileAsync(token, model.SiteName, model.Path, model.NewName);

                return(RedirectToAction(nameof(ViewFiles), new { appId = model.AppId, siteName = model.SiteName, path = model.Path.DetachPath() }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user, app.AppName);
                return(View(model));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RenameFile([FromRoute] string path)
        {
            var user = await GetCurrentUserAsync();

            var model = new RenameFileViewModel(user)
            {
                Path = path
            };

            return(View(model));
        }
Ejemplo n.º 3
0
        public RenameFileView(FileModel file)
        {
            RenameFileViewModel viewModel = new RenameFileViewModel(file);

            // Inicializa los componentes
            InitializeComponent();
            // Inicializa el ViewModel
            DataContext      = viewModel;
            viewModel.Close += (sender, result) =>
            {
                DialogResult = result.IsAccepted;
                Close();
            };
        }
Ejemplo n.º 4
0
        public void RenameFile(Common.Contracts.Images.IImageViewModel ImageViewModel)
        {
            if (ImageViewModel == null)
            {
                throw new ArgumentNullException("ImageViewModel");
            }

            using (var ViewModel = new RenameFileViewModel(ImageViewModel.FileInfo))
            {
                var Window = new RenameFileWindow();
                Window.DataContext           = ViewModel;
                Window.Owner                 = System.Windows.Application.Current.MainWindow;
                Window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                var Result = Window.ShowDialog();
                if (Result.HasValue && Result.Value)
                {
                    ImageViewModel.NotifyAllPropertiesChanged();
                }
            }
        }
Ejemplo n.º 5
0
        public IActionResult Update(RenameFileViewModel model)
        {
            var result = _commandDispatcher.Dispatch(new RenameFileCommand()
            {
                Id   = model.Id,
                Name = model.Name
            });

            if (result.IsSuccess)
            {
                return(RedirectToAction(nameof(List)));
            }
            if (!string.IsNullOrEmpty(result.Message))
            {
                ModelState.AddModelError("", result.Message);
            }
            foreach (var item in result.Errors)
            {
                ModelState.AddModelError("", item);
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> RenameFile(RenameFileViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(user);
                return(View(model));
            }
            try
            {
                await _filesService.RenameFileAsync(await AccessToken, user.SiteName, model.Path, model.NewFileName);

                return(RedirectToAction(nameof(ViewFiles), new { path = model.Path.DetachPath() }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user);
                return(View(model));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> RenameFile([FromRoute] string appId, [FromRoute] string siteName, [FromRoute] string path)
        {
            var user = await GetCurrentUserAsync();

            var app = await _dbContext.Apps.FindAsync(appId);

            if (app == null)
            {
                return(NotFound());
            }
            if (app.CreatorId != user.Id)
            {
                return(Unauthorized());
            }
            var model = new RenameFileViewModel(user)
            {
                AppId    = appId,
                SiteName = siteName,
                Path     = path,
                AppName  = app.AppName
            };

            return(View(model));
        }
Ejemplo n.º 8
0
 public RenameFileWindow(ImageModel file)
 {
     InitializeComponent();
     DataContext = new RenameFileViewModel(file);
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> Rename(RenameFileViewModel file)
        {
            RenameFileResult Result = await _mediator.Send(new UpdateFileNameCommand(file.FileId, file.NewName));

            return(HandleResult(Result, _mapper.Map <FileItemHeaderDto>(Result.File)));
        }
Ejemplo n.º 10
0
        public virtual async Task OnGetAsync()
        {
            var dto = await _service.GetAsync(Id);

            ViewModel = ObjectMapper.Map <FileInfoDto, RenameFileViewModel>(dto);
        }