protected async Task SetDefaultSeoValue(CreateOrEditTopicDto input) { if (input.Translations.HasData()) { input.Translations.ForEach(p => { if (p.MetaTitle.IsNullOrEmpty()) { p.MetaTitle = p.Name; } if (p.SeoSlug.IsNullOrEmpty()) { p.SeoSlug = p.Name.ToSlug(); } }); } if (input.MetaTitle.IsNullOrEmpty()) { input.MetaTitle = input.Name; } if (input.SeoSlug.IsNullOrEmpty()) { input.SeoSlug = input.Name.ToSlug(); } }
protected virtual async Task CreateUserAsync(CreateOrEditTopicDto input) { var entity = ObjectMapper.Map <Topic>(input); await postRepository.InsertAndGetIdAsync(entity); await CurrentUnitOfWork.SaveChangesAsync(); }
protected virtual async Task UpdateAsync(CreateOrEditTopicDto input) { var entity = await postRepository.GetAll() .Include(p => p.Translations) .FirstOrDefaultAsync(p => p.Id == input.Id); entity.Translations.Clear(); ObjectMapper.Map(input, entity); await postRepository.UpdateAsync(entity); }
public async Task CreateOrUpdate(CreateOrEditTopicDto input) { input.GetDefaultTranslation(); await SetDefaultSeoValue(input); if (input.Id != 0) { await UpdateAsync(input); } else { await CreateUserAsync(input); } }
public async Task <CreateOrEditTopicDto> GetForEdit(int?id) { var model = new CreateOrEditTopicDto(); var translations = await InitTranslationsAsync(); if (id == null) { model.Translations = translations; return(model); } var entity = await postRepository.GetAll() .Include(p => p.Translations) .FirstOrDefaultAsync(p => p.Id == id); entity.MapTo(model); model.Translations = model.Translations .Concat(translations) .DistinctBy(p => p.Language) .ToList(); return(model); }