public ContentResult AddTag([Bind(Exclude = "Id")] Tag tag) { string json; if (ModelState.IsValid) { var id = _blogRepository.AddTag(tag); json = JsonConvert.SerializeObject(new { id = id, success = true, message = "Tag added successfully." }); } else { json = JsonConvert.SerializeObject(new { id = 0, success = false, message = "Failed to add the tag." }); } return(Content(json, "application/json")); }
public async Task <IActionResult> Create(TagsVm tags) { if (ModelState.IsValid) { Tags model = _mapper.Map <Tags>(tags); _context.AddTag(model); _context.Commit(); return(RedirectToAction(nameof(Index))); } return(View(tags)); }
public async Task <Tag> AddTag(Tag tag) { return(await _blogRepository.AddTag(tag)); }