1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System.Threading.Tasks;
- using Datory;
- using GxPress.Entity.Topic;
- using GxPress.EnumConst;
- using GxPress.Repository.Interface;
- using GxPress.Repository.Interface.Note;
- using GxPress.Repository.Interface.Visit;
- using GxPress.Service.Interface.Visit;
- namespace GxPress.Service.Implement.Visit
- {
-
-
-
- public class VisitService : IVisitService
- {
- private readonly IVisitRepository _visitRepository;
- private readonly ITopicRepository _topicRepository;
- private readonly INoteRepository _noteRepository;
- private readonly ITopicAddresseeRepository _topicAddresseeRepository;
- private readonly IArticleRepository _articleRepository;
- public VisitService(IVisitRepository visitRepository, ITopicRepository topicRepository, INoteRepository noteRepository, ITopicAddresseeRepository topicAddresseeRepository, IArticleRepository articleRepository)
- {
- _visitRepository = visitRepository;
- _topicRepository = topicRepository;
- _noteRepository = noteRepository;
- _topicAddresseeRepository = topicAddresseeRepository;
- _articleRepository = articleRepository;
- }
-
-
-
-
-
-
-
- public async Task<bool> AddVisit(int userId, int typeId, int sourceId)
- {
- var visitBool = await _visitRepository.ExistsAsync(Q.Where(nameof(Entity.Visit.Visit.TypeId), typeId).Where(nameof(Entity.Visit.Visit.SourceId), sourceId).Where(nameof(Entity.Visit.Visit.UserId), userId));
- if (visitBool == false)
- {
- var visit = new Entity.Visit.Visit();
- visit.TypeId = typeId;
- visit.UserId = userId;
- visit.SourceId = sourceId;
- await _visitRepository.InsertAsync(visit);
-
- if (typeId == AllTypeConst.Article.GetHashCode())
- {
- var article = await _articleRepository.GetAsync(sourceId);
- article.ReadCount++;
- await _articleRepository.UpdateAsync(article);
- }
-
- if (typeId == AllTypeConst.Topic.GetHashCode())
- {
- var topic = await _topicRepository.GetAsync(sourceId);
- topic.ReadCount++;
- await _topicRepository.UpdateAsync(topic);
-
- await _topicAddresseeRepository.UpdateAsync(Q.Set(nameof(TopicAddressee.IsRead), true)
- .Where(nameof(TopicAddressee.TopicId), sourceId)
- .Where(nameof(TopicAddressee.UserId), userId));
- }
- if (typeId == AllTypeConst.Note.GetHashCode())
- {
- var note = await _noteRepository.GetAsync(sourceId);
- note.ReadCount++;
- await _noteRepository.UpdateAsync(note);
- }
- if (typeId == AllTypeConst.TopicNote.GetHashCode())
- {
- var note = await _noteRepository.GetAsync(sourceId);
- note.ReadCount++;
- await _noteRepository.UpdateAsync(note);
- }
- return true;
- }
- return false;
- }
-
-
-
-
-
-
- public async Task<int> GetCountAsync(int typeId, int sourceId)
- {
- return await _visitRepository.CountAsync(Q.Where(nameof(Entity.Visit.Visit.TypeId), typeId).Where(nameof(Entity.Visit.Visit.SourceId), sourceId));
- }
- }
- }
|