public async Task <IActionResult> Create(InviteEditModel model) { if (ModelState.IsValid) { try { PersonView person = await this.personService.GetCurrentPersonViewAsync(); InviteCode code = await this.inviteService.InsertAsync(model, person); return(this.Json(AjaxResult.CreateByContext(code))); } 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 async Task <IActionResult> ModifyAsk(PostEditModel model) { if (ModelState.IsValid) { try { await this.postService.ModifyAsync(model, this.User.GetUserId().Value); AjaxResult result = new AjaxResult { Message = "提交成功", Context = Url.Action("Details", "Question", new { id = model.Id }) }; return(this.Json(result)); } 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 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> 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> GetAll() { try { List <InviteCode> codes = await this.inviteService.GetAllAsync(); return(this.Json(AjaxResult.CreateByContext(codes))); } 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(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> GetAll() { try { List <Tag> tags = await this.tagService.GetAllAsync(); return(this.Json(AjaxResult.CreateByContext(tags))); } catch (Exception ex) { return(this.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> Search(string search) { try { List <Tag> tags = await this.tagService.SearchAsync(search); return(this.Json(AjaxResult.CreateByContext(tags))); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, 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 <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> 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> ChangeStatus([FromBody] Tag tag) { try { Tag newTag = await tagService.ChangeBestStatusAsync(tag, !tag.IsBest); return(this.Json(AjaxResult.CreateByContext(newTag))); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> LikeComment(Guid id) { try { await this.zanService.ZanCommentAsync(id); Comment comment = await this.commentService.GetByIdAsync(id); return(Json(AjaxResult.CreateByContext(comment.LikeNum))); } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> GetAll() { try { List <Topic> topics = await this.topicService.GetAllAsync(true, Library.Enums.SearchType.ALL); AjaxResult result = AjaxResult.CreateByContext(topics); return(this.Json(result)); } catch (Exception e) { AjaxResult result = AjaxResult.CreateByMessage(e.Message, false); return(this.Json(result)); } }
public async Task <IActionResult> LikePost(Guid id) { try { await this.zanService.ZanPostAsync(id); Post post = await this.postService.GetPostByIdAsync(id); return(Json(AjaxResult.CreateByContext(post.LikeNum))); } catch (Exception ex) { return(Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> ModifyAvatar(IFormFile file) { try { PersonView person = await this.personService.GetCurrentPersonViewAsync(); UploadInfo info = await this.uploadService.UploadImageAsync(file, true); await this.personService.ModifyAvatarAsync(person, info); return(this.Json(AjaxResult.CreateByContext(info.UrlPath))); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } }
public async Task <IActionResult> Register(AccountRegisterModel model) { if (User.Identity.IsAuthenticated) { return(this.Json(AjaxResult.CreateByMessage("您已经登录,请勿重复注册", false))); } else { if (ModelState.IsValid) { string code = HttpContext.Session.GetVerifyCode(); if (code.ToLower() == model.Code.ToLower()) { try { await personService.Register(model); return(this.Json(AjaxResult.CreateByMessage(""))); } 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> 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))); } }
/// <summary> /// 转换为AJAX返回对象 /// </summary> public static AjaxResult ToAjaxResult(this ModelStateDictionary modelState) { if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } if (modelState.IsValid) { return(AjaxResult.CreateByMessage("操作成功")); } else { Dictionary <string, string> err = modelState.GetAllErrors(); AjaxResult result = new AjaxResult(); result.Success = false; foreach (var item in err) { result.ErrorMessages.Add(item.Key, item.Value); } return(result); } }
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())); } }
public async Task <ActionResult> Edit(TopicEditModel model) { if (ModelState.IsValid) { try { Topic topic = await topicService.ModifyAsync(model); return(this.Json(AjaxResult.CreateByContext(topic))); } 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 async Task <ActionResult> Create(TagEditModel model) { if (ModelState.IsValid) { try { Tag tag = await tagService.CreateAsync(model); return(this.Json(AjaxResult.CreateByContext(tag))); } 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())); } }