private CastMessage CreateCastMessage(StickMan_Users_Cast_AudioData_UploadInformation uploadInfo, int currentUserId) { var message = new CastMessage { MessageInfo = new CastAudioInfo { Id = uploadInfo.Id, AudioFilePath = uploadInfo.AudioFilePath, UploadTime = uploadInfo.UploadTime.GetValueOrDefault(), Clicks = uploadInfo.ClickCount.GetValueOrDefault(), Title = uploadInfo.Title, TimePassedSinceUploaded = (DateTime.UtcNow - uploadInfo.UploadTime.GetValueOrDefault()).FormatDuration(), Duration = _audioFileService.GetDuration(uploadInfo.AudioFilePath).FormatDuration(), Likes = uploadInfo.LikePosts.Where(l => l.IsLike).Count(), Dislikes = uploadInfo.LikePosts.Where(l => !l.IsLike).Count(), Reposted = uploadInfo.PostUsers.Where(l => !l.IsReply).Count(), Replied = uploadInfo.PostUsers.Where(l => l.IsReply).Count() }, Listened = uploadInfo.UsersListened.Any(u => u.UserID == currentUserId) }; return(message); }
public CastMessage Save(string filePath, int userId, string title, int?replyPostId) { var message = new StickMan_Users_Cast_AudioData_UploadInformation { AudioFilePath = filePath, UserID = userId, ReadStatus = false, DeleteStatus = false, ClickCount = 0, UploadTime = DateTime.UtcNow, Title = title, ReplyPostId = replyPostId }; _unitOfWork.Repository <StickMan_Users_Cast_AudioData_UploadInformation>().Insert(message); _unitOfWork.Save(); var castMessage = CreateCastMessage(message, userId); var user = _unitOfWork.Repository <StickMan_Users>().GetSingle(u => u.UserID == userId); FillUserInfo(user, castMessage); return(castMessage); }