コード例 #1
0
        public void HandlePostClick(PostClickRequestModel model)
        {
            var post        = this.postRepository.GetById(model.Id);
            var ip          = this.ipAdressRepository.Filter(x => x.Value == model.Ip).FirstOrDefault();
            var uniqueClick = this.uniqueClickRepository.Filter(x => x.PostId == model.Id && x.IpAdressId == ip.Id).FirstOrDefault();

            if (post != null)
            {
                post.ClickCounter++;
                postRepository.SaveChanges();
            }

            if (ip == null)
            {
                this.ipAdressRepository.Create(new IpAdress {
                    Value = model.Ip
                });
                this.ipAdressRepository.SaveChanges();
                ip = this.ipAdressRepository.Filter(x => x.Value == model.Ip).FirstOrDefault();
            }

            if (uniqueClick != null)
            {
                uniqueClick.ClickCounter++;
            }
            else
            {
                this.uniqueClickRepository.Create(new UniqueClick {
                    ClickCounter = 1
                    , PostId     = post.Id
                    , IpAdressId = ip.Id
                });
            }

            this.postRepository.SaveChanges();
            this.uniqueClickRepository.SaveChanges();
            this.ipAdressRepository.SaveChanges();
        }
コード例 #2
0
 public ActionResult <string> Click([FromBody] PostClickRequestModel model)
 {
     this.postService.HandlePostClick(model);
     return(Ok());
 }