public void ChangeTo(Domain.Link link) { var model = _context.Links.FirstOrDefault(x => x.Id == link.Id); if (model == null) { throw new ArgumentException($"no link found with id {link.Id}"); } if (link?.Href.Value != null) { model.Href = link.Href.Value; } if (link?.Title.Value != null) { model.Title = link.Title.Value; } if (link?.Subtitle.Value != null) { model.Subtitle = link.Subtitle.Value; } if (link?.IconName.Value != null) { model.IconName = link.IconName.Value; } _context.SaveChanges(); _renderService.BuildUserPage(model.UserId); }
/// <exception cref="ArgumentException">thrown if no author found</exception> public int Add(Domain.Link link) { var model = new LinkModel(link); var author = _context.Users.FirstOrDefault(x => x.Id == link.User.Id); if (author == null) { throw new NoUserFoundException(); } // save link _context.Links.Add(model); // save because we need to generate id _context.SaveChanges(); // save link to link (xd) author.LinkIds.Add(model.Id); _context.SaveChanges(); _renderService.BuildUserPage(model.UserId); return(model.Id); }
public DetailLinkDtoWithUser(Domain.Link link) { id = link.Id; user = new UserTileDTO(link.User.Model); title = link.Title.Value; subtitle = link.Subtitle.Value; iconName = link.IconName.Value; href = link.Href.Value; createdAt = link.CreatedAt.ToUniversalTime().ToString("O"); }
public DetailLinkDto(Domain.Link link) { id = link.Id; user = link.User.Id; title = link.Title.Value; subtitle = link.Subtitle.Value; iconName = link.IconName.Value; href = link.Href.Value; createdAt = link.CreatedAt.ToUniversalTime().ToString("O"); }
private void Render(int userId, Theme theme, Domain.User data) { // get html as string using var reader = new StreamReader(_getTemplatePath(theme)); var html = reader.ReadToEnd(); // render // foreach (var variable in data.GetType().GetProperties()) { // html = html.Replace( // "{{ " + variable.Name + " }}", // variable.GetValue(data, null) as string ?? string.Empty // ); // } html = html.Replace("{{ name }}", data.Name.Value); html = html.Replace("{{ uid }}", data.Id.ToString()); html = html.Replace("{{ imagePath }}", data.ProfileImagePath?.Value); // render links var renderedLinks = ""; foreach (var linkRef in data.Links) { Domain.Link link = linkRef.Model; if (link == null) { continue; } var currLink = _linkHtml; currLink = currLink.Replace("{{ iconName }}", link.IconName.Value); currLink = currLink.Replace("{{ title }}", link.Title.Value); currLink = currLink.Replace("{{ subtitle }}", link.Subtitle.Value); currLink = currLink.Replace("{{ href }}", link.Href.Value); renderedLinks += currLink; } html = html.Replace("{% links %}", renderedLinks); // save new page File.WriteAllText(_getPagePath(data.Username.Value), html); }