コード例 #1
0
ファイル: AdminController.cs プロジェクト: kll195/JustBlog
        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"));
        }
コード例 #2
0
ファイル: TagsController.cs プロジェクト: dimkoug/BlogProject
 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));
 }
コード例 #3
0
 public async Task <Tag> AddTag(Tag tag)
 {
     return(await _blogRepository.AddTag(tag));
 }