public async Task <IActionResult> DeletePost(int id) { Post post = _blogUnitOfWork.Posts.GetAll().Include(p => p.Comments).Include(p => p.PostTags).Single(p => p.Id == id); var authorized = await _securityFacade.IsAuthorized(post, BlogConstants.DeleteActionName); if (authorized) { _blogUnitOfWork.Comments.DeleteMany(post.Comments); _blogUnitOfWork.Posts.Delete(post); await _blogUnitOfWork.SaveAsync(); } return(RedirectToAction("Index")); }
public async Task <OperationDetails> Create(UserDTO userDto) { ApplicationUser user = await _uow.UserManager.FindByEmailAsync(userDto.Email); if (user == null) { user = new ApplicationUser { Email = userDto.Email, UserName = userDto.Email }; await _uow.UserManager.CreateAsync(user, userDto.Password); // добавляем роль await _uow.UserManager.AddToRoleAsync(user.Id, userDto.Role); // создаем профиль клиента ClientProfile clientProfile = new ClientProfile { Id = user.Id, LastName = userDto.LastName, FirstName = userDto.FirstName }; _uow.ClientManager.Create(clientProfile); await _uow.SaveAsync(); return(new OperationDetails(true, "Registration was successful", "")); } else { return(new OperationDetails(false, "User with such email already exists", "Email")); } }
public async Task <IActionResult> Add(PostTagNameViewModel postTagNameViewModel) { Post post = postTagNameViewModel.Post; ApplicationUser author = await _securityFacade.GetCurrentUser(); post.PublicationDate = DateTime.Now; post.AuthorName = author.Name; post.AuthorUserId = author.Id; _blogUnitOfWork.Posts.Insert(post); AddTags(post, postTagNameViewModel.TagNames); await _blogUnitOfWork.SaveAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> WriteComment(PostCommentViewModel postCommentViewModel) { int id = postCommentViewModel.Post.Id; Comment comment = postCommentViewModel.Comment; Post post = await unitOfWork.Posts.GetById(id); if (post.Comments == null) { post.Comments = new List <Comment>(); } comment.PublicationDate = DateTime.Now; unitOfWork.Comments.Insert(comment); post.Comments.Add(comment); await unitOfWork.SaveAsync(); return(RedirectToAction("Read/" + post.Id.ToString())); }