public async Task <IActionResult> BlockPost(Guid postId) { try { PersonView loginPerson = await this.personService.GetCurrentPersonViewAsync(); Post post = await this.postService.GetPostByIdAsync(postId); if (post == null) { throw new Exception("该帖子不存在"); } bool isSelf = loginPerson.Id == post.PersonId; bool isAdmin = loginPerson.RoleType == RoleType.Admin || loginPerson.RoleType == RoleType.Master || loginPerson.RoleType == RoleType.SuperAdmin; if (isSelf || isAdmin) { await this.postService.BlockAsync(postId, loginPerson); return(Json(AjaxResult.CreateDefaultSuccess())); } else { throw new Exception("没有该操作的权限"); } } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> Edit(CommentEditModel model) { if (ModelState.IsValid) { try { if (model.Id == null) { throw new Exception("评论ID不能为空"); } Guid? loginUserId = this.User.GetUserId(); Comment comment = await this.commentService.GetByIdAsync(model.Id.Value); if (comment == null || comment.IsDelete) { throw new Exception("该评论不存在,或已被删除"); } else if (loginUserId == null || loginUserId.Value != comment.PersonId) { throw new Exception("没有该操作的权限"); } else if (string.IsNullOrWhiteSpace(model.Content)) { throw new Exception("内容不能为空"); } else { string htmlContent = this.htmlService.ClearHtml(model.Content); string textContent = this.htmlService.HtmlToText(htmlContent); if (string.IsNullOrWhiteSpace(htmlContent)) { throw new Exception("内容不能为空"); } else { await this.commentService.ModifyAsync(comment.Id, htmlContent, textContent); return(Json(AjaxResult.CreateDefaultSuccess())); } } } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
public IActionResult IsLogin() { if (this.HttpContext.User.Identity.IsAuthenticated) { return(this.Json(AjaxResult.CreateDefaultSuccess())); } else { return(this.Json(AjaxResult.CreateByMessage("", false))); } }
public async Task <IActionResult> SetTop(Guid postId, bool isTop) { try { await this.postService.SetTopAsync(postId, isTop); return(Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <ActionResult> Delete([FromBody] Tag tag) { try { await this.tagService.DeleteAsync(tag); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> Add(Guid postId) { try { await this.favoriteService.InsertFavoriteAsync(postId); return(Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> Delete(string code) { try { await this.inviteService.DeleteAsync(code); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> ChangeCodeRegister(bool status) { try { await this.inviteService.ChangeCodeRegister(status); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> ChangeStatus([FromBody] Topic topic) { try { int result = await this.topicService.ChangeStatusAsync(topic); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> RestoreMute(Guid id) { try { await this.personService.RestoreMuteByIdAsync(id); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> Delete(Guid id) { try { await this.commentService.DeleteAsync(id, this.User.GetUserId().Value); return(Json(AjaxResult.CreateDefaultSuccess())); } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> RoleModify(Guid id, RoleType role) { try { PersonView loginUser = await this.personService.GetCurrentPersonViewAsync(); PersonView DoUser = await this.personService.GetPersonViewAsync(id); if (DoUser == null) { throw new Exception("该用户不存在"); } else if (DoUser.RoleType == RoleType.SuperAdmin) { throw new Exception("无权修改网站管理员"); } else if (role == RoleType.SuperAdmin) { throw new Exception("无权设置为网站管理员"); } else if (loginUser.RoleType != RoleType.Admin && loginUser.RoleType != RoleType.SuperAdmin) { throw new Exception("仅管理员拥有操作权限"); } else if (loginUser.RoleType == RoleType.Admin && (role == RoleType.Admin || role == RoleType.SuperAdmin)) { throw new Exception("该操作无权限"); } else { await this.personService.ModifyRoleAsync(DoUser.Id, role); return(this.Json(AjaxResult.CreateDefaultSuccess())); } } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> ModifyPassword(ProfileModifyPasswordModel model) { if (ModelState.IsValid) { string code = HttpContext.Session.GetVerifyCode(); if (code.ToLower() == model.Code.ToLower()) { try { await personService.ModifyPasswordAsync(model); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { await HttpContext.Session.RefreshVerifyCodeAsync(); AjaxResult result = new AjaxResult(); result.Success = false; result.ErrorMessages.Add(nameof(model.Code), "验证码不正确,请重新输入"); return(this.Json(result)); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
public async Task <IActionResult> Info(ProfileInfoEditModel model) { if (ModelState.IsValid) { try { await this.personService.ModifyNickNameAsync(model); return(this.Json(AjaxResult.CreateDefaultSuccess())); } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { return(this.Json(ModelState.ToAjaxResult())); } }