/// <summary> /// Returns a new string in which all occurrences of the BaseUrl replaced with the UrlFormat. /// </summary> public Post ReplaceBaseUrlWithUrlFormat(Post post) { if (post == null) { return(post); } post.Content = _fileUrlHelper.ReplaceBaseUrlWithUrlFormat(post.Content); post.CoverUrl = _fileUrlHelper.ReplaceBaseUrlWithUrlFormat(post.CoverUrl); return(post); }
/// <summary> /// Handle the UpdateBlogSettingsCommand request. /// </summary> /// <param name="request">The UpdateBlogSettingsCommand request.</param> /// <param name="cancellationToken">A cancellation token.</param> public async Task <Result <BlogSettings> > Handle(UpdateBlogSettingsCommand request, CancellationToken cancellationToken) { var entity = await _context.BlogSettings.SingleOrDefaultAsync(); if (entity == null) { entity = new BlogSettings(); } entity.Title = request.Title; entity.Description = request.Description; entity.CoverUrl = _fileUrlHelper.ReplaceBaseUrlWithUrlFormat(request.CoverUrl); entity.CoverCaption = request.CoverCaption; entity.CoverLink = request.CoverLink; if (entity.Created == DateTime.MinValue) { _context.BlogSettings.Add(entity); } else { _context.BlogSettings.Update(entity); } var result = await _context.SaveChangesAsync(true, cancellationToken); if (!result.IsSuccess) { return(Result <BlogSettings> .Fail(result.Exception)); } return(Result <BlogSettings> .Success(entity)); }