Пример #1
0
        private async Task Prihlasit(OsobaDto neprihlaseny)
        {
            // pokud kliknu na přihlášení a následně na změnu termínu, dojde
            // - ke spuštění volání API pro přihlášení
            // - k nastavení State.Prihlaseni na null
            // - a k spuštění volní API pro načtení detailů termínu.
            // Pokud dojde k dokončení přihlášení před načtením termínu, je již State.Prihlaseni a State.Neprihlaseni null.
            // Pokud dokde k dokončení přihlášení po načtení termíu, jsou ve State.Prihlaseni a State.Neprihlaseni hodnoty nového termínu.
            // Takže nemůžeme volat Add/Remove nad State.Prihlaseni. Potřebujeme je volat nad kolekcemi platnými před spuštěním přihlašování.

            var prihlaseni   = State.Prihlaseni;
            var neprihlaseni = State.Neprihlaseni;

            await Progress.ExecuteInProgressAsync(async() => await TerminWebApiClient.PrihlasitAsync(State.AktualniTerminId.Value, neprihlaseny.Id));

            if (!prihlaseni.Contains(neprihlaseny))
            {
                prihlaseni.Add(neprihlaseny);
            }
            neprihlaseni.Remove(neprihlaseny);

            Toaster.Success($"{neprihlaseny.PrijmeniJmeno} přihlášen(a).");

            await LocalStorageService.SetItemAsync("PrefferedOsobaId", neprihlaseny.Id);

            PrefferedOsobaId = neprihlaseny.Id;
        }
Пример #2
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);
                }
            }
        }
Пример #3
0
        protected async Task Save()
        {
            await DataService.CustomFields.SaveCustomValue(SocialKey, SocialValue);

            StateHasChanged();
            Toaster.Success("Updated");
        }
Пример #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
        internal void CopySelectedOptionToClipboad(object raw)
        {
            var option = raw as Option;

            ClipboardHelpers.SetExcelData(option.LongText, option.Unit, 10, "à Fr.", 100, "Fr");
            Toaster.Success(Properties.Resources.copySuccessTitle);
        }
Пример #6
0
        protected async Task Save()
        {
            FieldValue = await JSRuntime.InvokeAsync <string>("commonJsFunctions.getEditorValue", "");

            await DataService.CustomFields.SaveCustomValue(FieldKey, FieldValue);

            StateHasChanged();
            Toaster.Success("Updated");
        }
Пример #7
0
        protected async Task Save()
        {
            await DataService.CustomFields.SaveCustomValue(DisqusKey, DisqusValue);

            await DataService.CustomFields.SaveCustomValue(DisqusSiteKey, DisqusSiteValue);

            StateHasChanged();
            Toaster.Success("Updated");
        }
Пример #8
0
        protected async Task SelectTheme(string theme)
        {
            var blogSettings = await DataService.CustomFields.GetBlogSettings();

            blogSettings.Theme = theme.ToLower();
            await DataService.CustomFields.SaveBlogSettings(blogSettings);

            Toaster.Success("Saved");
            await Load();
        }
Пример #9
0
        private async Task OnValidSubmitAsync()
        {
            // TODO: Sdílení Contracts!
            await NastenkaWebApiClient.VlozVzkazAsync(new WebApiClients.VzkazInputDto {
                AutorId = formData.AutorId.Value, Zprava = formData.Zprava
            });

            formData.Zprava = "";             // vyčistit formulář
            await LoadDataAsync();

            Toaster.Success("Vzkaz zapsán.");
        }
Пример #10
0
        protected async Task RemoveSubscription(int id)
        {
            var existing = DataService.Newsletters.Single(n => n.Id == id);

            if (existing != null)
            {
                DataService.Newsletters.Remove(existing);
                DataService.Complete();
                Toaster.Success("Removed");
                await GetSubscriptions(1);
            }
        }
Пример #11
0
        protected async Task Save()
        {
            try
            {
                await DataService.Authors.Save(Author);

                Toaster.Success("Saved");
            }
            catch (Exception ex)
            {
                Toaster.Error(ex.Message);
            }
        }
        protected async Task ValidSubmit()
        {
            OsobaInputDto novaOsoba = new OsobaInputDto()
            {
                Jmeno    = formData.Jmeno,
                Prijmeni = formData.Prijmeni,
                Email    = formData.Email
            };

            await Progress.ExecuteInProgressAsync(async() => await OsobaWebApiClient.VlozOsobuAsync(novaOsoba));

            Toaster.Success($"{novaOsoba.Prijmeni} {novaOsoba.Jmeno} založen(a).");
            NavigationManager.NavigateTo("/");
        }
Пример #13
0
        private async Task Odhlasit(OsobaDto prihlaseny)
        {
            var prihlaseni   = State.Prihlaseni;
            var neprihlaseni = State.Neprihlaseni;

            await Progress.ExecuteInProgressAsync(async() => await TerminWebApiClient.OdhlasitAsync(State.AktualniTerminId.Value, prihlaseny.Id));

            if (!neprihlaseni.Contains(prihlaseny))             // pokud došlo k doubleclicku, mohl se tam dostat
            {
                neprihlaseni.Add(prihlaseny);
                neprihlaseni.Sort((a, b) => a.PrijmeniJmeno.CompareTo(b.PrijmeniJmeno));
            }
            prihlaseni.Remove(prihlaseny);

            Toaster.Success($"{prihlaseny.PrijmeniJmeno} odhlášen(a).");
        }
Пример #14
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}");
            }
        }
Пример #15
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}");
            }
        }
        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);
            }
        }
Пример #17
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);
            }
        }
Пример #18
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);
            }
        }
Пример #19
0
        protected async Task HandleValidSubmit()
        {
            await DataService.CustomFields.SaveBlogSettings(Model);

            if (Model.Culture != CurrentCulture)
            {
                var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(Model.Culture));
                cookieValue = cookieValue.Replace("=", "%3D").Replace("|", "%7C");

                var test = await JSRuntime.InvokeAsync <string>(
                    "commonJsFunctions.writeCookie",
                    CookieRequestCultureProvider.DefaultCookieName,
                    cookieValue,
                    365
                    );
            }

            Toaster.Success("Saved");
        }
Пример #20
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}");
            }
        }
Пример #21
0
        public async Task Delete_Movie()
        {
            bool confirmed = await IJSRuntime.InvokeAsync <bool>("confirm", $"Are you shure you want to delete {Movie.Title}?");

            if (confirmed)
            {
                var response = await MoviesService.Delete(new IdRequest(Movie.Id));

                if (response.Ok)
                {
                    Toaster.Success("Movie deleted successfully");
                    await OnMovieDeleted.InvokeAsync(Movie.Id);
                }
                else
                {
                    Toaster.Success("Movie not deleted. Something went wrong");
                }
            }
        }
Пример #22
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"]);
                }
            }
        }
        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"]);
                }
            }
        }
Пример #24
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;
            }
        }
Пример #25
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 (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);
            }
        }
Пример #26
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);
            }
        }
Пример #27
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");
            }
        }
Пример #28
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);
            }
        }
Пример #29
0
 protected void Uploaded()
 {
     StateHasChanged();
     Toaster.Success("Saved");
 }
Пример #30
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);
            }
        }