/// <summary> /// Adds a <paramref name="tag"/> to a given <paramref name="fact"/>. /// </summary> /// <param name="fact">The fact that the tag will be added to.</param> /// <param name="tag">The tag that will be added to the fact.</param> /// <example> /// <code> /// Fact newFact = new Fact(){ /// Context = "This is a fact." /// }; /// Tag newTag = new Tag(){ /// Name = "Tag name" /// }; /// AddTag(newFact, newTag); /// foreach(var tag in newFact.Tags.Select(t => t.Tag).ToList()){ /// if(tag == newTag){ /// Console.WriteLine($"The new fact has the tag {tag.Name}"); /// } /// } /// </code> /// </example> public void AddTag(Fact fact, Tag tag) { fact.Tags.Add(new FactsTags() { FactId = fact.FactId, TagId = tag.TagId }); context.SaveChanges(); }
/// <summary> /// Creates a new tag with the given <paramref name="name"/> /// </summary> /// <param name="name">The name of the tag.</param> /// <returns>The id of the created tag.</returns> /// <example> /// <code> /// Guid tagId = CreateTag("My tag"); /// Tag tag = context.Tags.Where(t => t.Name == name).FirstOrDefault(); /// Console.WriteLine(tag.Name); /// </code> /// </example> public Guid CreateTag(string name) { Tag tag = new Tag() { Name = name.First().ToString().ToUpper() + name.Substring(1).ToLower() }; context.Tags.Add(tag); context.SaveChanges(); return(tag.TagId); }
/// <summary> /// Creates a new user with a <paramref name="name"/>, <paramref name="email"/> & <paramref name="password"/> and adds it to the database. /// </summary> /// <param name="email">The email of the new user.</param> /// <param name="name">The name of the new user.</param> /// <param name="password">The password of the new user.</param> /// <returns>The id of the created user.</returns> /// <example> /// <code> /// User user = GetUserById(CreateUser("*****@*****.**", "My name", "My password")); /// Console.WriteLine($"Name: {user.Name}; Email: {user.Email}; Password: {user.Password}"); /// </code> /// </example> /// <see cref="GetUserById(Guid)"/> public Guid CreateUser(string email, string name, string password) { User user = new User() { Name = name, Email = email, Password = password }; context.Users.Add(user); context.SaveChanges(); return(user.UserId); }
/// <summary> /// Creates a new theme with all required fields - theme name, image & type of the image. /// </summary> /// <param name="name">The name of the theme.</param> /// <param name="image">Shown image for the theme.</param> /// <param name="imageContentType">The type of the image</param> /// <returns>The id of the created theme.</returns> /// <example> /// <code> /// byte[] image; /// using (var ms = new MemoryStream()) /// { /// request.ImageUploaded.CopyTo(ms); /// image = ms.ToArray(); /// } /// Theme theme = GetThemeById(CreateTheme("My new theme", image, request.ImageUploaded.ContentType)); /// Console.WriteLine(theme.Name); /// </code> /// </example> /// <see cref="GetThemeById(Guid)"/> public Guid CreateTheme(string name, byte[] image, string imageContentType) { Theme theme = new Theme() { Name = name, Image = image, ImageContentType = imageContentType }; context.Themes.Add(theme); context.SaveChanges(); return(theme.ThemeId); }