Exemplo n.º 1
0
        protected async Task Load()
        {
            int authorId = await GetAuthorId();

            CurrentField = new SocialField {
                AuthorId = authorId
            };
            SocialFields = await DataService.CustomFields.GetSocial(authorId);

            StateHasChanged();
        }
Exemplo n.º 2
0
        public async Task <ActionResult <SocialField> > PostSocialAccounts([FromBody] SocialField field)
        {
            try
            {
                await _data.CustomFields.SaveSocial(field);

                var created = _data.CustomFields.Single(f => f.Name == field.Name);
                return(Created($"/api/customfields/{created.Id}", created));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Exemplo n.º 3
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}");
            }
        }
Exemplo n.º 4
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");
            }
        }