public async Task <string> SendPasswordResetCode(SendEmailCodeInput sendEmailCode) { var user = await GetUserByChecking(sendEmailCode.Email); if (user.IsEmailConfirmed == false) { throw new LinCmsException("邮件未激活,无法通过此邮件找回密码!"); } user.SetNewPasswordResetCode(); int rand6Value = new Random().Next(100000, 999999); var message = new MimeMessage(); message.From.Add(new MailboxAddress(_mailKitOptions.UserName, _mailKitOptions.UserName)); message.To.Add(new MailboxAddress(user.Username, user.Email)); message.Subject = $"你此次重置密码的验证码是:{rand6Value}"; message.Body = new TextPart("html") { Text = $@"{user.Nickname},您好!</br>你此次重置密码的验证码如下,请在 30 分钟内输入验证码进行下一步操作。</br>如非你本人操作,请忽略此邮件。</br>{rand6Value}" }; await _userRepository.UpdateAsync(user); await _emailSender.SendAsync(message); await RedisHelper.SetAsync(user.Email, rand6Value, 30 * 60); return(user.PasswordResetCode); }
public async Task <Article> UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto) { Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne(); if (article.CreateUserId != _currentUser.Id) { throw new LinCmsException("您无权修改他人的随笔"); } if (article == null) { throw new LinCmsException("没有找到相关随笔"); } _mapper.Map(updateArticleDto, article); article.WordNumber = article.Content.Length; article.ReadingTime = article.Content.Length / 400; await _articleRepository.UpdateAsync(article); ArticleDraft articleDraft = _mapper.Map <ArticleDraft>(article); bool exist = await _articleDraftRepository.Select.AnyAsync(r => r.Id == article.Id); if (exist) { await _articleDraftRepository.UpdateAsync(articleDraft); } else { await _articleDraftRepository.InsertAsync(articleDraft); } return(article); }
public async Task <UnifyResponseDto> UpdateAsync(Guid id, [FromBody] CreateUpdateClassifyDto updateClassify) { Classify classify = await _classifyRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (classify == null) { throw new LinCmsException("该数据不存在"); } if (classify.CreateUserId != _currentUser.Id) { throw new LinCmsException("您无权编辑他人的分类专栏"); } bool exist = await _classifyRepository.Select.AnyAsync(r => r.ClassifyName == updateClassify.ClassifyName && r.Id != id && r.CreateUserId == _currentUser.Id); if (exist) { throw new LinCmsException($"分类专栏[{updateClassify.ClassifyName}]已存在"); } _mapper.Map(updateClassify, classify); await _classifyRepository.UpdateAsync(classify); return(UnifyResponseDto.Success("更新分类专栏成功")); }
public async Task UpdateAsync(long id, CreateUpdateBookDto updateBook) { Book book = _bookRepository.Select.Where(r => r.Id == id).ToOne(); if (book == null) { throw new LinCmsException("没有找到相关书籍"); } bool exist = _bookRepository.Select.Any(r => r.Title == updateBook.Title && r.Id != id); if (exist) { throw new LinCmsException("图书已存在"); } //book.Image = updateBook.Image; //book.Title = updateBook.Title; //book.Author = updateBook.Author; //book.Summary = updateBook.Summary; //book.Summary = updateBook.Summary; //使用AutoMapper方法简化类与类之间的转换过程 Mapper.Map(updateBook, book); await _bookRepository.UpdateAsync(book); }
public async Task UpdateAsync(int id, CreateUpdateBaseItemDto updateBaseItem) { BaseItem baseItem = await _baseItemRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (baseItem == null) { throw new LinCmsException("该数据不存在"); } bool typeExist = await _baseTypeRepository.Select.AnyAsync(r => r.Id == updateBaseItem.BaseTypeId); if (!typeExist) { throw new LinCmsException("请选择正确的类别"); } bool exist = await _baseItemRepository.Select.AnyAsync(r => r.BaseTypeId == updateBaseItem.BaseTypeId && r.ItemCode == updateBaseItem.ItemCode && r.Id != id); if (exist) { throw new LinCmsException($"编码[{updateBaseItem.ItemCode}]已存在"); } _mapper.Map(updateBaseItem, baseItem); await _baseItemRepository.UpdateAsync(baseItem); }
public async Task UpdateAsync(Guid id, CreateUpdateChannelDto updateChannel) { Channel channel = await _channelRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (channel == null) { throw new LinCmsException("该数据不存在"); } bool exist = await _channelRepository.Select.AnyAsync(r => r.ChannelName == updateChannel.ChannelName && r.Id != id && r.ChannelCode == updateChannel.ChannelCode); if (exist) { throw new LinCmsException($"技术频道[{updateChannel.ChannelName}]已存在"); } Mapper.Map(updateChannel, channel); await _channelRepository.UpdateAsync(channel); await _channelTagRepository.DeleteAsync(r => r.ChannelId == id); var channelTagLists = new List <ChannelTag>(); updateChannel.TagIds?.ForEach(r => { channelTagLists.Add(new ChannelTag(id, r)); }); await _channelTagRepository.InsertAsync(channelTagLists); }
public async Task UpdateLikeQuantityAysnc(Guid subjectId, int likesQuantity) { Comment comment = await _commentRepository.Select.Where(r => r.Id == subjectId).ToOneAsync(); comment.UpdateLikeQuantity(likesQuantity); await _commentRepository.UpdateAsync(comment); }
public async Task UpdateAsync(long id, UpdateGroupDto updateGroupDto) { LinGroup group = await _groupRepository.Where(r => r.Id == id).FirstAsync(); Mapper.Map(updateGroupDto, group); await _groupRepository.UpdateAsync(group); }
public async Task UpdateAsync(Guid id, CreateUpdateTagDto updateTag) { Tag tag = await _tagRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (tag == null) { throw new LinCmsException("该数据不存在"); } bool exist = await _tagRepository.Select.AnyAsync(r => r.TagName == updateTag.TagName && r.Id != id); if (exist) { throw new LinCmsException($"标签[{updateTag.TagName}]已存在"); } Mapper.Map(updateTag, tag); await _tagRepository.UpdateAsync(tag); }
public async Task UpdateAsync(long id, CreateUpdateDocDto updateDoc) { Doc doc = await Repository.Select.Where(r => r.Id == id).ToOneAsync(); if (doc == null) { throw new LinCmsException("该数据不存在"); } _mapper.Map(updateDoc, doc); await Repository.UpdateAsync(doc); }
public async Task UpdateAsync(Guid id, bool isAudit) { MessageBoard messageBoard = await _messageBoardRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (messageBoard == null) { throw new LinCmsException("没有找到相关留言"); } messageBoard.IsAudit = isAudit; await _messageBoardRepository.UpdateAsync(messageBoard); }
public async Task UpdateAsync(Guid id, CreateUpdateArticleDto updateArticleDto) { Article article = _articleRepository.Select.Where(r => r.Id == id).ToOne(); if (article.CreateUserId != CurrentUser.Id) { throw new LinCmsException("您无权修改他人的随笔"); } if (article == null) { throw new LinCmsException("没有找到相关随笔"); } if (article.ClassifyId != updateArticleDto.ClassifyId) { await _classifyService.UpdateArticleCountAsync(article.ClassifyId, -1); await _classifyService.UpdateArticleCountAsync(updateArticleDto.ClassifyId, 1); } Mapper.Map(updateArticleDto, article); article.WordNumber = article.Content.Length; article.ReadingTime = article.Content.Length / 800; await _articleRepository.UpdateAsync(article); ArticleDraft articleDraft = Mapper.Map <ArticleDraft>(article); bool exist = await _articleDraftRepository.Select.AnyAsync(r => r.Id == article.Id); if (exist) { await _articleDraftRepository.UpdateAsync(articleDraft); } else { await _articleDraftRepository.InsertAsync(articleDraft); } }
/// <summary> /// 权限标签上的Permission改变时,删除数据库中存在的无效权限,并生成新的权限。 /// </summary> /// <returns></returns> public async Task SeedPermissionAsync(List <PermissionDefinition> linCmsAttributes, CancellationToken cancellationToken) { List <LinPermission> insertPermissions = new List <LinPermission>(); List <LinPermission> updatePermissions = new List <LinPermission>(); List <LinPermission> allPermissions = await _permissionRepository.Select.ToListAsync(); Expression <Func <LinGroupPermission, bool> > expression = u => false; Expression <Func <LinPermission, bool> > permissionExpression = u => false; allPermissions.ForEach(permissioin => { if (linCmsAttributes.All(r => r.Permission != permissioin.Name)) { expression = expression.Or(r => r.PermissionId == permissioin.Id); permissionExpression = permissionExpression.Or(r => r.Id == permissioin.Id); } }); int effectRows = await _permissionRepository.DeleteAsync(permissionExpression, cancellationToken); effectRows += await _groupPermissionRepository.DeleteAsync(expression, cancellationToken); _logger.LogInformation($"删除了{effectRows}条数据"); linCmsAttributes.ForEach(r => { LinPermission permissionEntity = allPermissions.FirstOrDefault(u => u.Module == r.Module && u.Name == r.Permission); if (permissionEntity == null) { insertPermissions.Add(new LinPermission(r.Permission, r.Module, r.Router)); } else { bool routerExist = allPermissions.Any(u => u.Module == r.Module && u.Name == r.Permission && u.Router == r.Router); if (!routerExist) { permissionEntity.Router = r.Router; updatePermissions.Add(permissionEntity); } } }); await _permissionRepository.InsertAsync(insertPermissions, cancellationToken); _logger.LogInformation($"新增了{insertPermissions.Count}条数据"); await _permissionRepository.UpdateAsync(updatePermissions, cancellationToken); _logger.LogInformation($"更新了{updatePermissions.Count}条数据"); }
public async Task <UnifyResponseDto> AuditAsync(Guid id, bool isAudit) { Article article = await _articleRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (article == null) { throw new LinCmsException("没有找到相关随笔"); } article.IsAudit = isAudit; await _articleRepository.UpdateAsync(article); return(UnifyResponseDto.Success()); }
public async Task <UnifyResponseDto> UpdateAsync(Guid id, bool isAudit) { Comment comment = _commentAuditBaseRepository.Select.Where(r => r.Id == id).ToOne(); if (comment == null) { throw new LinCmsException("没有找到相关评论"); } comment.IsAudit = isAudit; await _commentAuditBaseRepository.UpdateAsync(comment); return(UnifyResponseDto.Success()); }
/// <summary> /// 本地文件上传,秒传(根据lin_file表中的md5,与当前文件的路径是否在本地),如果不在,重新上传,覆盖文件表记录 /// </summary> /// <param name="file"></param> /// <param name="key"></param> /// <returns></returns> public async Task <FileDto> UploadAsync(IFormFile file, int key = 0) { string md5 = LinCmsUtils.GetHash <MD5>(file.OpenReadStream()); LinFile linFile = await _fileRepository.Where(r => r.Md5 == md5 && r.Type == 1).OrderByDescending(r => r.CreateTime).FirstAsync(); if (linFile != null && File.Exists(Path.Combine(_hostingEnv.WebRootPath, linFile.Path))) { return(new FileDto { Id = linFile.Id, Key = "file_" + key, Path = linFile.Path, Url = _fileStorageOption.LocalFile.Host + linFile.Path }); } long id; var(path, len) = await this.LocalUploadAsync(file); if (linFile == null) { LinFile saveLinFile = new LinFile() { Extension = Path.GetExtension(file.FileName), Md5 = md5, Name = file.FileName, Path = path, Type = 1, Size = len }; id = (await _fileRepository.InsertAsync(saveLinFile)).Id; } else { linFile.Path = path; await _fileRepository.UpdateAsync(linFile); id = linFile.Id; } return(new FileDto { Id = id, Key = "file_" + key, Path = path, Url = _fileStorageOption.LocalFile.Host + path }); }
public async Task ChangePasswordAsync(LinUserIdentity linUserIdentity, string newpassword) { string encryptPassword = EncryptUtil.Encrypt(newpassword); if (linUserIdentity == null) { linUserIdentity = new LinUserIdentity(LinUserIdentity.Password, "", encryptPassword, DateTime.Now); await _userIdentityRepository.InsertAsync(linUserIdentity); } else { linUserIdentity.Credential = encryptPassword; await _userIdentityRepository.UpdateAsync(linUserIdentity); } }
public Task ChangePasswordAsync(LinUserIdentity linUserIdentity, string newpassword, string salt) { string encryptPassword = _cryptographyService.Encrypt(newpassword, salt); if (linUserIdentity == null) { linUserIdentity = new LinUserIdentity(LinUserIdentity.Password, "", encryptPassword, DateTime.Now); return(_userIdentityRepository.InsertAsync(linUserIdentity)); } else { linUserIdentity.Credential = encryptPassword; return(_userIdentityRepository.UpdateAsync(linUserIdentity)); } }
public async Task UpdateAsync(ResourceDto resourceDto) { LocalResource entity = await _resourceRepository.Select.Where(r => r.Id == resourceDto.Id).ToOneAsync(); if (entity == null) { throw new LinCmsException("该数据不存在"); } bool exist = await _resourceRepository.Select.AnyAsync(r => r.Key == resourceDto.Key && r.Id != resourceDto.Id && r.CultureId == resourceDto.CultureId); if (exist) { throw new LinCmsException($"Key[{resourceDto.Key}]已存在"); } _mapper.Map(resourceDto, entity); await _resourceRepository.UpdateAsync(entity); }
public async Task UpdateLikeQuantity(Guid subjectId, int likesQuantity) { Comment comment = _commentRepository.Select.Where(r => r.Id == subjectId).ToOne(); if (comment.IsAudit == false) { throw new LinCmsException("该评论因违规被拉黑"); } if (likesQuantity < 0) { if (comment.LikesQuantity < -likesQuantity) { return; } } comment.LikesQuantity += likesQuantity; await _commentRepository.UpdateAsync(comment); //_commentRepository.UpdateDiy.Set(r => r.LikesQuantity + likesQuantity).Where(r => r.Id == subjectId).ExecuteAffrows(); }
public async Task UpdateAsync(int id, CreateUpdateBaseTypeDto updateBaseType) { BaseType baseType = await _baseTypeRepository.Select.Where(r => r.Id == id).ToOneAsync(); if (baseType == null) { throw new LinCmsException("该数据不存在"); } bool exist = await _baseTypeRepository.Select.AnyAsync(r => r.TypeCode == updateBaseType.TypeCode && r.Id != id); if (exist) { throw new LinCmsException($"基础类别-编码[{updateBaseType.TypeCode}]已存在"); } _mapper.Map(updateBaseType, baseType); await _baseTypeRepository.UpdateAsync(baseType); }
public async Task ChangePasswordAsync(LinUserIdentity linUserIdentity, string newpassword) { string encryptPassword = EncryptUtil.Encrypt(newpassword); if (linUserIdentity == null) { linUserIdentity = new LinUserIdentity() { IdentityType = LinUserIdentity.Password, Identifier = "", Credential = encryptPassword }; await _userIdentityRepository.InsertAsync(linUserIdentity); } else { linUserIdentity.Credential = encryptPassword; await _userIdentityRepository.UpdateAsync(linUserIdentity); } }
public async Task <CultureDto> UpdateAsync(CultureDto cultureDto) { LocalCulture localCulture = await _cultureRepository.Select.Where(r => r.Id == cultureDto.Id).ToOneAsync(); if (localCulture == null) { throw new LinCmsException("该数据不存在"); } bool exist = await _cultureRepository.Select.AnyAsync(r => r.Name == cultureDto.Name && r.Id != cultureDto.Id); if (exist) { throw new LinCmsException($"Name[{cultureDto.Name}]已存在"); } Mapper.Map(cultureDto, localCulture); await _cultureRepository.UpdateAsync(localCulture); return(Mapper.Map <CultureDto>(localCulture)); }
public async Task UpdateAsync(long id, UpdateGroupDto updateGroupDto) { LinGroup group = await _groupRepository.Where(r => r.Id == id).FirstAsync(); if (group.IsStatic) { if (group.Name != updateGroupDto.Name) { throw new LinCmsException("静态权限组标识符不修改!"); } } bool anyName = await _groupRepository.Where(r => r.Name == updateGroupDto.Name && r.Id != id).AnyAsync(); if (anyName) { throw new LinCmsException($"权限组标识符:{updateGroupDto.Name}已存在!", ErrorCode.RepeatField); } Mapper.Map(updateGroupDto, group); await _groupRepository.UpdateAsync(group); }