コード例 #1
0
        protected void SaveCustom()
        {
            if (string.IsNullOrEmpty(CurrentField.Name) || string.IsNullOrEmpty(CurrentField.Content))
            {
                Toaster.Error("Name and content required");
            }
            else
            {
                try
                {
                    var existing = DataService.CustomFields.Single(
                        f => f.AuthorId == Author.Id && f.Name == CurrentField.Name);

                    if (existing == null)
                    {
                        DataService.CustomFields.Add(CurrentField);
                        DataService.Complete();
                        CurrentField = new CustomField {
                            AuthorId = Author.Id, Name = "", Content = ""
                        };
                    }
                    Toaster.Success(Localizer["completed"]);
                }
                catch (Exception ex)
                {
                    Toaster.Error(ex.Message);
                }
            }
        }
コード例 #2
0
        public async Task HandleValidSubmitAsync()
        {
            await FileUploadService.UploadAsync(file, Model.FileGuid);

            var plugin = PluginTester.LoadPlugin(Model.FileGuid);

            if (plugin == null)
            {
                Toaster.Error("Vložený soubor není platná knihovna.");
                return;
            }

            try
            {
                PluginTester.TestImplementation(plugin);
            }
            catch (Exception e)
            {
                Toaster.Error(e.Message, "Chyba implementace");
                return;
            }

            await PlayerService.InsertNewPlayerAsync(new PlayerVM
            {
                Name     = Model.Name,
                Password = Model.Password,
                FileGuid = Model.FileGuid,
                League   = (League)Convert.ToInt32(Model.League)
            });

            Toaster.Info("Nový hráč vložen.");
            NavigationManager.NavigateTo("/players");
        }
コード例 #3
0
        protected async Task DeletePlayerAsync()
        {
            if (string.IsNullOrEmpty(DeletePassword))
            {
                Toaster.Error("Zadejte prosím heslo pro smazání.");
                return;
            }

            modalRef.Hide();

            if (DeletePlayerId == null)
            {
                return;
            }

            try
            {
                await PlayerService.DeleteAsync(DeletePlayerId.Value, DeletePassword);
            }
            catch (Exception e)
            {
                Toaster.Error(e.Message);
                return;
            }


            DeletePlayerId = null;

            Toaster.Info("Hráč byl smazán.");

            await OnParametersSetAsync();
        }
コード例 #4
0
        protected async Task ChangePwd()
        {
            try
            {
                if (await FeatureManager.IsEnabledAsync(nameof(AppFeatureFlags.Demo)))
                {
                    Toaster.Error("Running in demo mode - change password disabled");
                }
                else
                {
                    var authState = await AuthenticationStateTask;
                    var user      = await UserManager.GetUserAsync(authState.User);

                    var result = await UserManager.ChangePasswordAsync(user, PwdModel.OldPassword, PwdModel.NewPassword);

                    if (!result.Succeeded)
                    {
                        Toaster.Error("Error changing password");
                    }
                    else
                    {
                        Toaster.Success(Localizer["saved"]);
                    }
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #5
0
        private bool IsAssemblyValid()
        {
            AssemblyLoadContext assemblyLoadContext = new CollectibleAssemblyLoadContext();

            try
            {
                Assembly plugin;
                try
                {
                    plugin = PluginTester.LoadPlugin(assemblyLoadContext, Model.FileGuid);
                }
                catch (Exception e)
                {
                    Toaster.Error($"Vložený soubor není platná knihovna. ({e.Message})");
                    return(false);
                }

                try
                {
                    PluginTester.TestImplementation(plugin);
                }
                catch (Exception e)
                {
                    Toaster.Error(e.Message, "Chyba implementace");
                    return(false);
                }
            }
            finally
            {
                assemblyLoadContext.Unload();
            }

            return(true);
        }
コード例 #6
0
        protected async override Task OnInitializedAsync()
        {
            Thread = await DataService.GetThreadById(int.Parse(threadId));

            if (Thread == null)
            {
                Toaster.Error("Thread not found");
            }
        }
コード例 #7
0
ファイル: Inspection.cs プロジェクト: sergius2ch/ProjectHR
 public static void NotifyError(Logger log, string msg)
 {
     log.Warn(msg);
     if (CurrentException != null)
     {
         log.Error(CurrentException);
     }
     Toaster.Error("Error", msg);
     CurrentException = null;
 }
コード例 #8
0
        protected async Task Save()
        {
            try
            {
                await DataService.Authors.Save(Author);

                Toaster.Success("Saved");
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #9
0
        protected async Task RemoveField(int id)
        {
            var existing = DataService.CustomFields.Single(f => f.Id == id);

            if (existing != null)
            {
                DataService.CustomFields.Remove(existing);
                DataService.Complete();
                Toaster.Success(Localizer["completed"]);
                await Load();
            }
            else
            {
                Toaster.Error($"Error removing field #{id}");
            }
        }
コード例 #10
0
        protected async Task RankField(int id, bool up)
        {
            var existing = DataService.CustomFields.Single(f => f.Id == id);

            if (existing != null)
            {
                var fieldArray = existing.Name.Split('|');
                if (fieldArray.Length > 2)
                {
                    int oldRank = int.Parse(fieldArray[2]);
                    int newRank = 1;

                    if (up && oldRank > 1)
                    {
                        newRank = oldRank - 1;
                    }
                    if (!up)
                    {
                        newRank = oldRank + 1;
                    }

                    var toUpdate = new SocialField
                    {
                        Id       = id,
                        Title    = fieldArray[1].Capitalize(),
                        Icon     = $"fa-{fieldArray[1]}",
                        Rank     = newRank,
                        Name     = $"{fieldArray[0]}|{fieldArray[1]}|{newRank}",
                        AuthorId = existing.AuthorId,
                        Content  = existing.Content
                    };
                    await DataService.CustomFields.SaveSocial(toUpdate);

                    DataService.Complete();
                    Toaster.Success(Localizer["completed"]);
                    await Load();
                }
                else
                {
                    Toaster.Error($"Error - unexpected field format: {existing.Name}");
                }
            }
            else
            {
                Toaster.Error($"Error moving field #{id}");
            }
        }
コード例 #11
0
        protected async Task Publish(int id)
        {
            try
            {
                var post = await DataService.BlogPosts.GetItem(p => p.Id == id);

                post.Published = DateTime.UtcNow;
                var saved = await DataService.BlogPosts.SaveItem(post);

                DataService.Complete();

                if (!AppSettings.DemoMode)
                {
                    // send newsletters on post publish
                    var section = Configuration.GetSection(Constants.ConfigSectionKey);
                    if (section != null)
                    {
                        var apiKey = section.GetValue <string>("SendGridApiKey");
                        if (!string.IsNullOrEmpty(apiKey) && apiKey != "YOUR-SENDGRID-API-KEY")
                        {
                            var pager = new Pager(1, 10000);
                            var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                            var emails   = items.Select(i => i.Email).ToList();
                            var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                            int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                            if (count > 0)
                            {
                                Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                            }
                        }
                    }
                }
                Toaster.Success("Saved");

                await OnUpdate.InvokeAsync("publish");

                StateHasChanged();
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #12
0
        protected async Task Remove(int id)
        {
            try
            {
                var post = DataService.BlogPosts.Find(p => p.Id == id).FirstOrDefault();
                DataService.BlogPosts.Remove(post);
                DataService.Complete();

                await HideCallback.InvokeAsync("remove");

                Toaster.Success("Removed");
                StateHasChanged();
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #13
0
        public async Task Feature(int id)
        {
            try
            {
                var post = DataService.BlogPosts.Find(p => p.Id == id).FirstOrDefault();
                post.IsFeatured = false;
                DataService.Complete();

                await OnUpdate.InvokeAsync("unfeature");

                StateHasChanged();
                Toaster.Success("Saved");
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #14
0
        protected void RemoveField(int id)
        {
            var existing = DataService.CustomFields.Single(f => f.Id == id);

            if (existing != null)
            {
                DataService.CustomFields.Remove(existing);
                DataService.Complete();
                Toaster.Success(Localizer["completed"]);
                CurrentField = new CustomField {
                    AuthorId = Author.Id, Name = "", Content = ""
                };
                UserFields = DataService.CustomFields.Find(f => f.AuthorId == Author.Id);
            }
            else
            {
                Toaster.Error($"Error removing field #{id}");
            }
        }
コード例 #15
0
        protected async Task Send()
        {
            if (FeatureManager.IsEnabledAsync(nameof(AppFeatureFlags.Demo)).Result)
            {
                Toaster.Info(Localizer["demo-disabled"]);
            }
            else
            {
                bool result = await EmailService.SendEmail(Model.SendTo, Model.Subject, Model.Content);

                if (result)
                {
                    Toaster.Success(Localizer["email-sent-success"]);
                }
                else
                {
                    Toaster.Error(Localizer["email-sent-error"]);
                }
            }
        }
コード例 #16
0
        protected async Task Send()
        {
            if (AppSettings.DemoMode)
            {
                Toaster.Info(Localizer["demo-disabled"]);
            }
            else
            {
                bool result = await EmailService.SendEmail(Model.SendTo, Model.Subject, Model.Content);

                if (result)
                {
                    Toaster.Success(Localizer["email-sent-success"]);
                }
                else
                {
                    Toaster.Error(Localizer["email-sent-error"]);
                }
            }
        }
コード例 #17
0
        public void ShowInfo(string title, string body, InfoType type)
        {
            switch (type)
            {
            case InfoType.Success:
                Toaster.Success(body);
                break;

            case InfoType.Info:
                Toaster.Info(body);
                break;

            case InfoType.Warn:
                Toaster.Warning(body);
                break;

            case InfoType.Error:
                Toaster.Error(body);
                break;
            }
        }
コード例 #18
0
ファイル: Drafts.razor.cs プロジェクト: rlebowitz/Blogifier
        protected async Task Publish(int id)
        {
            try
            {
                var post = await DataService.BlogPosts.GetItem(p => p.Id == id);

                post.Published = DateTime.UtcNow;
                var saved = await DataService.BlogPosts.SaveItem(post);

                DataService.Complete();

                if (FeatureManager.IsEnabledAsync(nameof(AppFeatureFlags.Email)).Result)
                {
                    // send newsletters on post publish when email feature enabled
                    var pager = new Pager(1, 10000);
                    var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                    var emails   = items.Select(i => i.Email).ToList();
                    var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                    int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                    if (count > 0)
                    {
                        Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                    }
                }
                Toaster.Success("Saved");

                await OnUpdate.InvokeAsync("publish");

                StateHasChanged();
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #19
0
        protected async Task Save()
        {
            if (string.IsNullOrEmpty(CurrentField.Title) || string.IsNullOrEmpty(CurrentField.Content))
            {
                Toaster.Error("Name and content required");
            }
            else
            {
                var newField = new SocialField
                {
                    Title    = CurrentField.Title.Capitalize(),
                    Content  = CurrentField.Content,
                    Icon     = $"fa-{CurrentField.Title.ToLower()}",
                    AuthorId = await GetAuthorId(),
                    Name     = $"social|{CurrentField.Title.ToLower()}|1",
                    Rank     = 1
                };
                await DataService.CustomFields.SaveSocial(newField);
                await Load();

                Toaster.Success("Updated");
            }
        }
コード例 #20
0
        protected async Task Remove(int id)
        {
            try
            {
                bool confirmed = await JSRuntime.InvokeAsync <bool>("confirm", $"{Localizer["confirm-delete"]}");

                if (confirmed)
                {
                    var post = DataService.BlogPosts.Find(p => p.Id == id).FirstOrDefault();
                    DataService.BlogPosts.Remove(post);
                    DataService.Complete();

                    await HideCallback.InvokeAsync("remove");

                    Toaster.Success("Removed");
                    StateHasChanged();
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #21
0
        public async Task HandleValidSubmitAsync()
        {
            IsDisabledButton = true;
            StateHasChanged();

            var league = (League)Convert.ToInt32(Model.League);

            TournamentService.NewGamePlayed += NewGamePlayedEvent;
            try
            {
                var games = await TournamentService.NewTournamentAsync(league);

                await TournamentService.InsertNewTournamentAsync(league, games);
            }
            catch (Exception e)
            {
                Toaster.Error(e.Message);
                NavigationManager.NavigateTo("/tournaments");
                return;
            }

            Toaster.Info("Turnaj byl odehrán.");
            NavigationManager.NavigateTo("/tournaments");
        }
コード例 #22
0
        protected async Task SavePost(PostAction postAction)
        {
            try
            {
                var content = await JSRuntime.InvokeAsync <string>("commonJsFunctions.getEditorValue", "");

                Post.Content = content;

                if (string.IsNullOrEmpty(Post.Title))
                {
                    Toaster.Error("Post title required");
                }
                else if (string.IsNullOrEmpty(Post.Content))
                {
                    Toaster.Error("Post content required");
                }
                else
                {
                    PostItem saved;
                    if (Post.Id == 0)
                    {
                        var authState = await AuthenticationStateTask;
                        var author    = await DataService.Authors.GetItem(
                            a => a.AppUserName == authState.User.Identity.Name);

                        Post.Author      = author;
                        Post.Slug        = GetSlug(Post.Title);
                        Post.Description = Post.Title;

                        saved = await DataService.BlogPosts.SaveItem(Post);
                    }
                    else
                    {
                        var item = await DataService.BlogPosts.GetItem(p => p.Id == Post.Id);

                        item.Content     = Post.Content;
                        item.Title       = Post.Title;
                        item.Description = Post.Description;
                        item.Categories  = Post.Categories;

                        if (postAction == PostAction.Unpublish)
                        {
                            item.Published = DateTime.MinValue;
                        }

                        if (postAction == PostAction.Publish)
                        {
                            item.Published = SystemClock.Now();
                        }

                        saved = await DataService.BlogPosts.SaveItem(item);
                    }

                    if (saved != null && saved.Id > 0)
                    {
                        if (postAction == PostAction.Publish && FeatureManager.IsEnabledAsync(nameof(AppFeatureFlags.Email)).Result)
                        {
                            var pager = new Pager(1, 10000);
                            var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                            var emails   = items.Select(i => i.Email).ToList();
                            var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                            int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                            if (count > 0)
                            {
                                Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                            }
                        }
                        Toaster.Success("Saved");
                        Post   = saved;
                        PostId = Post.Id;
                        StateHasChanged();
                    }
                    else
                    {
                        Toaster.Error("Post was not saved");
                    }
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
コード例 #23
0
        protected async Task SavePost(PostAction postAction)
        {
            try
            {
                var content = await JSRuntime.InvokeAsync <string>("commonJsFunctions.getEditorValue", "");

                Post.Content = content;

                if (string.IsNullOrEmpty(Post.Title))
                {
                    Toaster.Error("Post title required");
                }
                else if (string.IsNullOrEmpty(Post.Content))
                {
                    Toaster.Error("Post content required");
                }
                else
                {
                    PostItem saved;
                    if (Post.Id == 0)
                    {
                        var authState = await AuthenticationStateTask;
                        var author    = await DataService.Authors.GetItem(
                            a => a.AppUserName == authState.User.Identity.Name);

                        Post.Author      = author;
                        Post.Slug        = Post.Title.ToSlug();
                        Post.Description = Post.Title;

                        saved = await DataService.BlogPosts.SaveItem(Post);
                    }
                    else
                    {
                        var item = await DataService.BlogPosts.GetItem(p => p.Id == Post.Id);

                        item.Content     = Post.Content;
                        item.Title       = Post.Title;
                        item.Description = Post.Description;
                        item.Categories  = Post.Categories;

                        if (postAction == PostAction.Unpublish)
                        {
                            item.Published = DateTime.MinValue;
                        }

                        saved = await DataService.BlogPosts.SaveItem(item);
                    }
                    DataService.Complete();

                    if (postAction == PostAction.Publish && !AppSettings.DemoMode)
                    {
                        var section = Configuration.GetSection(Constants.ConfigSectionKey);
                        if (section != null)
                        {
                            var apiKey = section.GetValue <string>("SendGridApiKey");
                            if (!string.IsNullOrEmpty(apiKey) && apiKey != "YOUR-SENDGRID-API-KEY")
                            {
                                var pager = new Pager(1, 10000);
                                var items = await DataService.Newsletters.GetList(e => e.Id > 0, pager);

                                var emails   = items.Select(i => i.Email).ToList();
                                var blogPost = DataService.BlogPosts.Single(p => p.Id == saved.Id);

                                int count = await EmailService.SendNewsletters(blogPost, emails, NavigationManager.BaseUri);

                                if (count > 0)
                                {
                                    Toaster.Success(string.Format(Localizer["email-sent-count"], count));
                                }
                            }
                        }
                    }

                    Toaster.Success("Saved");
                    Post   = saved;
                    PostId = Post.Id;
                    StateHasChanged();
                }
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }