Пример #1
0
 public void Delete(PostTextVisit entity)
 {
     if (_db.Entry(entity).State == EntityState.Detached)
     {
         _db.Attach(entity);
     }
     _db.PostTextVisits.Remove(entity);
 }
Пример #2
0
 public void Update(PostTextVisit entity)
 {
     if (_db.Entry(entity).State == EntityState.Detached)
     {
         _db.PostTextVisits.Attach(entity);
     }
     _db.Entry(entity).State = EntityState.Modified;
 }
Пример #3
0
        public async Task <IActionResult> ReadMore(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                _notification.AddWarningToastMessage("پست مورد نطر یافت نشد دوباره امتحان کنید");
                return(RedirectToAction("Home", "Index"));
            }
            var Post = await _db.PostTextRepository.GetByIdAsync(id);

            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            ViewBag.UserId = userId;
            var savepost = _db.SavePostRepository.Where(p => p.UserId == userId).ToList();

            ViewBag.UserCount = savepost.Count();
            var ip = HttpContext.Connection.RemoteIpAddress.ToString();

            Post.Groups = await _db.GroupRepository.GetByIdAsync(Post.GroupId);

            Post.Users = await _db.UserRepository.GetByIdAsync(Post.UserId);

            var GetVisit = _db.PostTextVisitRepository.Where(p => p.PostId == id && p.Ip == ip).ToList();

            if (GetVisit.Count == 0)
            {
                var visit = new PostTextVisit()
                {
                    Ip     = ip,
                    PostId = id
                };
                await _db.PostTextVisitRepository.InsertAsync(visit);

                Post.Visit += 1;
                _db.PostTextRepository.Update(Post);
                _db.SaveChange();
            }
            var Comments = _db.CommentRepository.Where(p => p.PostId == Post.Id).OrderByDescending(p => p.CreatedTime).ToList();

            if (Comments != null)
            {
                foreach (var item in Comments)
                {
                    item.Users = await _db.UserRepository.GetByIdAsync(item.UserId);
                }
            }
            var viewModel = new ReadMoreViewModel()
            {
                PostText = Post,
                Comments = Comments
            };

            return(View(viewModel));
        }
Пример #4
0
 public async Task InsertAsync(PostTextVisit entity)
 {
     await _db.PostTextVisits.AddAsync(entity);
 }
Пример #5
0
 public void Insert(PostTextVisit entity)
 {
     _db.PostTextVisits.Add(entity);
 }