/// <summary> /// 创建下载记录 /// </summary> /// <param name="userId">下载用户UserId</param> /// <param name="attachmentId">附件Id</param> /// <returns>创建成功返回true,否则返回false</returns> public bool Create(long userId, long attachmentId) { Attachment attachment = _attachmentRepository.Get(attachmentId); if (attachment == null) { return(false); } IUserService userService = DIContainer.Resolve <IUserService>(); IUser user = userService.GetUser(userId); if (user == null) { return(false); } if (IsDownloaded(userId, attachmentId)) { return(_attachmentDownloadRepository.UpdateLastDownloadDate(userId, attachmentId)); } else { AttachmentDownloadRecord record = AttachmentDownloadRecord.New(attachment); record.UserId = userId; record.UserDisplayName = user.DisplayName; long id = 0; long.TryParse(_attachmentDownloadRepository.Insert(record).ToString(), out id); return(id > 0); } }
/// <summary> /// 创建新的下载记录 /// </summary> /// <param name="entity">下载记录实体</param> /// <returns>下载记录Id</returns> public new object Insert(AttachmentDownloadRecord entity) { object id = base.Insert(entity); if (Convert.ToInt64(id) > 0) { // 缓存服务 ICacheService cacheService = DIContainer.Resolve <ICacheService>(); string cacheKey = GetCacheKey_RecordIds_AttachmentIds(entity.UserId); Dictionary <long, long> ids_AttachmentIds = cacheService.Get <Dictionary <long, long> >(cacheKey); if (ids_AttachmentIds != null && !ids_AttachmentIds.Values.Contains(entity.AttachmentId)) { ids_AttachmentIds[entity.Id] = entity.AttachmentId; cacheService.Set(cacheKey, ids_AttachmentIds, CachingExpirationType.UsualObjectCollection); } } return(id); }