Пример #1
0
        public async Task <IActionResult> ShareFileAttachment(ShareFileViewModel model)
        {
            var email = model.AttachmentEmail?.Trim() ?? string.Empty;

            // Ensure we have an email to share with
            if (string.IsNullOrEmpty(email))
            {
                // Add alert
                _alerter.Danger(T["An email address is required!"]);

                // Redirect back to file
                return(Redirect(_contextFacade.GetRouteUrl(new RouteValueDictionary()
                {
                    ["area"] = "Plato.Files",
                    ["controller"] = "Admin",
                    ["action"] = "Edit",
                    ["id"] = model.FileId
                })));
            }

            // Get current user
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // We need to be authenticated to add the invite
            if (user == null)
            {
                return(Unauthorized());
            }

            // Create the invite
            var invite = await _fileInviteStore.CreateAsync(new FileInvite()
            {
                FileId        = model.FileId,
                Email         = email,
                CreatedUserId = user.Id,
                CreatedDate   = DateTimeOffset.Now
            });

            // Share the invite
            if (invite != null)
            {
                var result = await _shareInviteService.SendAttachmentInviteAsync(invite);

                if (result.Succeeded)
                {
                    _alerter.Success(T["File Shared Successfully!"]);
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        if (!string.IsNullOrEmpty(error.Description))
                        {
                            _alerter.Danger(T[error.Description]);
                        }
                    }
                }
            }

            // Redirect back to file
            return(Redirect(_contextFacade.GetRouteUrl(new RouteValueDictionary()
            {
                ["area"] = "Plato.Files",
                ["controller"] = "Admin",
                ["action"] = "Edit",
                ["id"] = model.FileId
            })));
        }