Ejemplo n.º 1
0
        private void GenerateOrder(IEnumerable <EmployeePortalPage> obj, JToken list)
        {
            for (int i = 0; i < list.Count(); i++)
            {
                int parentId = int.Parse(list[i]["id"].ToString());
                EmployeePortalPage parent = obj.FirstOrDefault(c => c.BaseID == parentId && c.Status == VersionableItemStatus.Live);

                if (list[i]["children"] != null && parent != null)
                {
                    var clist = list[i]["children"];
                    for (int j = 0; j < clist.Count(); j++)
                    {
                        int childId = int.Parse(clist[j]["id"].ToString());
                        var item    = obj.SingleOrDefault(c => c.BaseID == childId && c.Status == VersionableItemStatus.Live);

                        if (item != null)
                        {
                            item.Order    = j + 1;
                            item.ParentId = parent.BaseID;
                            item.Slug     = String.Format("{0}/{1}", parent.Slug, Slug.Create(true, item.Title));
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Slug_WithDefaultOptions(string text, string expected)
        {
            var options = new SlugOptions();
            var slug    = Slug.Create(text, options);

            Assert.AreEqual(expected, slug);
        }
Ejemplo n.º 3
0
        private async Task <IEnumerable <Category> > BuildCategories()
        {
            var entities = await _categoryService.GetCategories();

            var categoryIds = entities.Select(cat => cat.Id);
            var categories  = new List <Category>();

            foreach (var category in entities)
            {
                Category cat = new Category()
                {
                    Id   = category.Id,
                    Name = category.Name
                };

                cat.Slug = Slug.Create(cat.Name);

                var categoryTags = await _categoryService.GetTags(cat.Id);

                cat.Tags = categoryTags.Select(tag => {
                    var slug = Slug.Create(tag);
                    return(new Tag(tag, slug));
                });

                categories.Add(cat);
            }

            return(categories);
        }
Ejemplo n.º 4
0
        private async Task <IEnumerable <Tag> > BuildTags()
        {
            var popular = await _postService.GetPopularTags(15);

            var tags = popular.Select(tag => new Tag(tag, Slug.Create(tag)));

            return(tags);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Uses the properties in SlugFields to generate a slug.
        /// If you override this, you must return a completed slug (i.e. 'test-object')
        /// If you return null or empty, the slug will not be updated
        /// </summary>
        /// <param name="obj">object that should be searched for properties</param>
        /// <returns>Slug to be saved to database</returns>
        public virtual string GenerateSlug(T obj)
        {
            var type       = obj.GetType();
            var properties = type.GetProperties().Where(d => SlugFields.Contains(d.Name)).ToArray();

            ICollection <string> slugValues = properties.Select(property => property.GetValue(obj, null).ToString()).ToList();

            return(Slug.Create(true, slugValues.ToArray()));
        }
Ejemplo n.º 6
0
        public void Slug_Lowercase(string text, string expected)
        {
            var options = new SlugOptions
            {
                CasingTransformation = CasingTransformation.ToLowerCase,
            };
            var slug = Slug.Create(text, options);

            Assert.Equal(expected, slug);
        }
Ejemplo n.º 7
0
        public override string GenerateSlug(EmployeePortalPage obj)
        {
            if (obj.ParentId != null)
            {
                var parent = _repo.FindBy(x => x.Status == VersionableItemStatus.Live && x.ID == obj.ParentId).FirstOrDefault();
                return(string.Format("{0}/{1}", parent.Slug, Slug.Create(true, obj.Title)));
            }

            return(Slug.Create(true, obj.Title));
        }
Ejemplo n.º 8
0
        public void Slug_Lowercase(string text, string expected)
        {
            var options = new SlugOptions
            {
                ToLower = true
            };
            var slug = Slug.Create(text, options);

            Assert.AreEqual(expected, slug);
        }
Ejemplo n.º 9
0
        public NoteViewModelProfile()
        {
            CreateMap <NoteDto, NoteViewModel>()
            .ForMember(vm => vm.Categories, conf => conf.Ignore())
            .AfterMap((dto, vm) =>
            {
                vm.Categories = dto.NoteCategories.Select(t => t.CategoryId).ToArray();
                vm.Tags       = string.Join(',', dto.NoteTags.Select(nt => nt.Title));
            });

            CreateMap <NoteViewModel, NoteDto>()
            .ForMember(dest => dest.Slug, o => o.MapFrom(so => Slug.Create(so.Title)))
            .ForMember(dest => dest.Slug, o => o.MapFrom((sourceVm, destDto) =>
            {
                // Adding
                switch (sourceVm.Id)
                {
                case default(int)when string.IsNullOrWhiteSpace(sourceVm.Slug):
                    return(Slug.Create(sourceVm.Title));

                case default(int):
                    return(sourceVm.Slug);
                }

                // Editing
                if (!string.IsNullOrWhiteSpace(sourceVm.Slug))
                {
                    return(sourceVm.Slug);
                }
                else
                {
                    return(Slug.Create(sourceVm.Title));
                }
            }))
            .ForMember(dto => dto.NoteCategories, conf => conf.Ignore())
            .AfterMap((vm, dto) =>
            {
                dto.NoteCategories = vm.Categories.Select(id => new NoteCategoryDto()
                {
                    CategoryId = id
                }).ToList();

                if (!string.IsNullOrWhiteSpace(vm.Tags))
                {
                    dto.NoteTags = vm.Tags.Split(",").Select(input => new NoteTagDto()
                    {
                        NoteId = dto.Id,
                        Title  = input.Trim(),
                        Slug   = Slug.Create(input.Trim())
                    }).ToList();
                }
            });
        }
Ejemplo n.º 10
0
        public ProjectModelProfile()
        {
            CreateMap <ProjectDto, ProjectModel>()
            .ForMember(dest => dest.IsOngoingProject, o => o.MapFrom(source => !source.DateFinished.HasValue))
            .ForPath(dest => dest.MonthFrom, o => o.MapFrom(source => source.DateStarted.Month))
            .ForPath(dest => dest.YearFrom, o => o.MapFrom(source => source.DateStarted.Year))
            .ForMember(dest => dest.MonthTo, os =>
            {
                os.PreCondition(c => c.DateFinished.HasValue);
                os.MapFrom(source => source.DateFinished.Value.Month);
            })
            .ForMember(dest => dest.YearTo, o =>
            {
                o.PreCondition(c => c.DateFinished.HasValue);
                o.MapFrom(source => source.DateFinished.Value.Year);
            });

            CreateMap <ProjectModel, ProjectDto>()
            .ForMember(dest => dest.Slug, o =>
            {
                o.MapFrom((sourceModel, destDto) =>
                {
                    // Adding
                    switch (sourceModel.Id)
                    {
                    case default(int)when string.IsNullOrWhiteSpace(sourceModel.Slug):
                        return(Slug.Create(sourceModel.Title));

                    case default(int):
                        return(sourceModel.Slug);
                    }

                    // Editing
                    if (!string.IsNullOrWhiteSpace(sourceModel.Slug))
                    {
                        return(sourceModel.Slug);
                    }
                    else
                    {
                        return(Slug.Create(sourceModel.Title));
                    }
                });
            })
            .ForMember(dest => dest.DateStarted, o => o.MapFrom(source => new DateTime(source.YearFrom, source.MonthFrom, 1)))
            .ForMember(dest => dest.DateFinished, os =>
            {
                os.PreCondition(c => c.MonthTo.HasValue);
                os.PreCondition(c => c.YearTo.HasValue);
                os.MapFrom(source => new DateTime(source.YearTo.Value, source.MonthTo.Value, 1));
            });
        }
Ejemplo n.º 11
0
        public CategoryViewModelProfile()
        {
            CreateMap <CategoryDto, CategoryViewModel>();

            CreateMap <CategoryViewModel, CategoryDto>()
            .ForMember(dest => dest.Slug, o => o.MapFrom((source, dest) =>
            {
                if (string.IsNullOrWhiteSpace(source.Slug))
                {
                    return(Slug.Create(source.Title));
                }

                return(source.Slug);
            }));
        }
Ejemplo n.º 12
0
        public ActionResult Edit(CategoryViewModel categoryViewModel)
        {
            if (ModelState.IsValid)
            {
                var category = _mapper.Map <CategoryViewModel, CategoryDto>(categoryViewModel);

                if (string.IsNullOrWhiteSpace(category.Slug))
                {
                    category.Slug = Slug.Create(category.Title);
                }

                _categoryService.Update(category);
                SetClientSideNotificationMessage(_messageProvider.SuccessMessage(OperationType.Update, "category"));
                return(RedirectToAction("List"));
            }

            return(View(categoryViewModel));
        }
Ejemplo n.º 13
0
        public void Slug_WithDefaultOptions(string text, string expected)
        {
            var slug = Slug.Create(text);

            Assert.Equal(expected, slug);
        }
Ejemplo n.º 14
0
        public void UpdateNoteTags(int noteId, IEnumerable <string> updatedTags)
        {
            Note note = Set.Find(noteId);

            if (note == null)
            {
                throw new ArgumentException($"No note with given id {noteId}", nameof(note));
            }

            updatedTags = updatedTags.ToArray();

            List <Tag>    availableTagEntities = Context.Set <Tag>().ToList();
            List <string> availableTags        = availableTagEntities.Select(t => t.Title).ToList();

            List <NoteTag> noteTags    = Context.Set <NoteTag>().Where(nt => nt.NoteId == noteId).ToList();
            List <string>  currentTags =
                (from tag in availableTagEntities join noteTag in noteTags on tag.Id equals noteTag.TagId select tag.Title).ToList();

            var newTags         = updatedTags.Except(availableTags).ToArray();
            var removedTags     = currentTags.Except(updatedTags).ToArray();
            var existingNewTags = updatedTags.Intersect(availableTags).ToArray();

            foreach (var newTag in newTags)
            {
                Tag tag = new Tag {
                    Title = newTag, Slug = Slug.Create(newTag)
                };
                NoteTag noteTag = new NoteTag {
                    NoteId = note.Id, TagId = tag.Id, Tag = tag, Note = note
                };

                Context.Set <Tag>().Add(tag);
                Context.Set <NoteTag>().Add(noteTag);
            }

            foreach (var removedTag in removedTags)
            {
                foreach (var noteTag in noteTags)
                {
                    if (noteTag.Tag.Title.Equals(removedTag, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Context.Set <NoteTag>().Remove(noteTag);
                        break;
                    }
                }
            }

            foreach (var existingNewTag in existingNewTags)
            {
                foreach (var availableTag in availableTagEntities)
                {
                    if (existingNewTag.Equals(availableTag.Title, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (currentTags.Any(existingTag => existingTag == existingNewTag))
                        {
                            break;
                        }

                        NoteTag noteTag = new NoteTag {
                            NoteId = note.Id, TagId = availableTag.Id, Note = note
                        };
                        note.NoteTags.Add(noteTag);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public override LiquidExpressionResult ApplyTo(ITemplateContext ctx, ILiquidValue liquidExpression)
        {
            var strArray = ValueCaster.RenderAsString(liquidExpression).Split();

            // TODO: add ability to toggle lower-case on/off
            return(LiquidExpressionResult.Success(StringUtils.Eval(liquidExpression, x => Slug.Create(true, strArray))));
        }