public ActionResult AddOrEdit(int Id, string Title, string ShortDescription, string Description, string Meta, string UrlSlug, string Category, string[] tags, bool Published, DateTime PostedOn) { Post post; IList <Tag> tagsList = new List <Tag>(); IList <Tag> resultTagsList = new List <Tag>(); tagsList = _blogRepository.GetAllTags().ToList(); foreach (var tag in tagsList) { if (tags.Contains(tag.Name)) { resultTagsList.Add(tag); } } if (Id == 0) { post = new Post() { Title = Title, ShortDescription = ShortDescription, Description = Description, Meta = Meta, UrlSlug = UrlSlug, Category = _blogRepository.GetAllCategories().Where(c => c.Id == Int32.Parse(Category)).FirstOrDefault(), Published = Published, PostedOn = DateTime.Now, Modified = DateTime.Now, Tags = resultTagsList }; _blogRepository.AddOrUpdatePost(post); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { post = new Post() { Id = Id, Title = Title, ShortDescription = ShortDescription, Description = Description, Meta = Meta, UrlSlug = UrlSlug, Category = _blogRepository.GetAllCategories().Where(c => c.Id == Int32.Parse(Category)).FirstOrDefault(), Published = Published, PostedOn = PostedOn, Modified = DateTime.Now, Tags = resultTagsList }; _blogRepository.AddOrUpdatePost(post); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } }