public async Task <IActionResult> Create([Bind("Id,Name")] Tag tag) { if (ModelState.IsValid) { await _tagServices.CreateTag(tag.Name); return(RedirectToAction(nameof(Index))); } return(View(tag)); }
/// <summary> /// Checks if a tag exists in the context. Creates a new Tag if it does not. /// </summary> /// <param name="name">The Name of the new Tag.</param> /// <returns>Tag</returns> private async Task <Tag> CreateTagIfDoesntExist(string name) { name = name.ToLower().Trim(); if (!await _context.Tags.AnyAsync(t => t.Name.ToLower() == name)) { await _tagServices.CreateTag(name); } var tag = _context.Tags.FirstOrDefault(t => t.Name.ToLower() == name); return(tag); }
public async Task <IActionResult> Post(string name) { var model = await _tagServices.CreateTag(name); return(Ok(model)); }