public ActionResult Edit(CreatePostDataModel createPostDataModel) { StudentDataModel currentStudent = SessionCurrentStudent(); postService.Edit(createPostDataModel); return(RedirectToAction("Index", "Posts")); }
public ActionResult Create(CreatePostDataModel createPostDataMode) { StudentDataModel currentStudent = SessionCurrentStudent(); createPostDataMode.AuthorId = currentStudent.Id; postService.Create(createPostDataMode); return(RedirectToAction("Index", "Posts", currentStudent)); }
public void Create(CreatePostDataModel createPostDataModel) { var tags = createPostDataModel.Tags.Split(new[] { ',' }, options: StringSplitOptions.RemoveEmptyEntries); var newPostDataModel = new PostDataModel { AuthorId = createPostDataModel.AuthorId, Created = DateTime.Now, Content = createPostDataModel.Content, Tags = new List <TagDataModel>() }; foreach (var tag in tags) { newPostDataModel.Tags.Add(new TagDataModel { Name = tag.Trim() }); } var newPost = Mapper.Map <PostDataModel, Post>(source: newPostDataModel); UnitOfWork.Posts.Create(newPost); UnitOfWork.Save(); }
public void Edit(CreatePostDataModel createPostDataModel) { var editPost = UnitOfWork.Posts.Get(createPostDataModel.Id); editPost.Content = createPostDataModel.Content; var tags = createPostDataModel.Tags.Split(new[] { ',' }, options: StringSplitOptions.RemoveEmptyEntries); foreach (var tag in tags) { if (editPost.Tags.Any(t => t.Name == tag.Trim())) { continue; } var newTag = new Tag() { Name = tag.Trim() }; UnitOfWork.Tags.Create(newTag); editPost.Tags.Add(newTag); } UnitOfWork.Posts.Update(editPost); UnitOfWork.Save(); }