public async Task <ActionResult> LikeUser(int id, int recepientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repoo.GetLike(id, recepientId);

            if (like != null)
            {
                return(BadRequest("You Already like this user"));
            }

            if (await _repoo.GetUser(recepientId) == null)
            {
                return(NotFound());
            }

            like = new Models.Like
            {
                LikerId = id,
                LikeeId = recepientId
            };
            _repoo.Add <Models.Like>(like);
            if (await _repoo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to Like User"));
        }
 public ActionResult LikePictureDetails(int id)
 {
     Models.Like thePictureLike = database.Likes.SingleOrDefault(c => c.picture_id == id);
     thePictureLike.read = 1;
     database.SaveChanges();
     return(RedirectToAction("LikePictureIndex", new { id = thePictureLike.picture_id }));
 }
        public async Task <IActionResult> LikeUser(int userId, int reciepentId)
        {
            if (userId != int.Parse(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var like = await _datingRepository.GetLike(userId, reciepentId);

            if (like != null)
            {
                return(BadRequest("You already liked this user"));
            }
            if (await _datingRepository.GetUser(reciepentId) == null)
            {
                return(NotFound());
            }

            like = new Models.Like
            {
                LikerId = userId,
                LikeeId = reciepentId
            };

            _datingRepository.Add <Like>(like);
            if (await _datingRepository.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Failed to like user"));
        }
Exemple #4
0
        public async Task <IActionResult> LikeUser(int id, int recepientId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repo.GetLike(id, recepientId);

            if (like != null)
            {
                return(BadRequest("Ya le diste like a este usuario"));
            }

            if (await _repo.GetUser(recepientId) == null)
            {
                return(NotFound());
            }

            like = new Models.Like
            {
                LikerId = id,
                LikeeId = recepientId
            };

            _repo.add <Like>(like);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Ha ocurrido una falla al dar like al usuario"));
        }
Exemple #5
0
        public ActionResult like(Models.Like like, String LikeBlogID)//点赞博文的ID
        {
            int                BlogID = Convert.ToInt32(LikeBlogID);
            String             UserID = Session["UserID"].ToString();
            List <Models.Like> likes  = db.Likes.Where(n => n.BlogID == BlogID).Where(m => m.UserID == UserID).ToList(); //判断用户是否点赞过

            if (likes.Count() == 0)                                                                                      //没赞过
            {
                like.BlogID = BlogID;
                like.UserID = Session["UserID"].ToString();
                db.Likes.Add(like);
                db.SaveChanges();
                return(Content("<script language=javascript>self.location=document.referrer;</script>"));
                //return Content("<script>window.open('" + Url.Content("~/UserBlog/seeblogdetails?BlogID=" + BlogID + "") + "', '_self')</script>");
            }
            else
            {//用户已经赞过需要取消赞
                foreach (Models.Like h in likes)
                {
                    db.Likes.Remove(h);
                }
                db.SaveChanges();
                return(Content("<script language=javascript>self.location=document.referrer;</script>"));
                // return Content("<script>window.open('" + Url.Content("~/UserBlog/seeblogdetails?BlogID=" + BlogID + "") + "', '_self')</script>");
            }
        }
        public async Task <ActionResult> LikeUser(int id, int likeeId)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Forbid());
            }

            var like = await this._repo.GetLike(id, likeeId);

            if (like != null)
            {
                return(BadRequest("You already liked this user."));
            }

            if (await this._repo.GetUser(likeeId) == null)
            {
                return(BadRequest($"User {id} couldn't be liked."));
            }

            like = new Models.Like
            {
                LikeeId = likeeId,
                LikerId = id
            };

            this._repo.Add <Like>(like);

            if (await this._repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest($"Failed to like user {likeeId}."));
        }
Exemple #7
0
        public void Add(string productId, string userId)
        {
            var like = new Models.Like
            {
                User = _userDal.GetUser(userId)
            };

            _productDal.AddLike(int.Parse(productId), like);
        }
        public ActionResult UnLikePicture(int id)
        {
            Models.Like    likePicture = database.Likes.SingleOrDefault(p => p.picture_id == id);
            Models.Picture thePicture  = database.Pictures.SingleOrDefault(p => p.picture_id == id);
            database.Likes.Remove(likePicture);
            database.SaveChanges();

            return(RedirectToAction("Details", new { id = thePicture.profile_id }));
        }
        public ActionResult UnlikePic(int id)
        {
            int personId = Int32.Parse(Session["person_id"].ToString());

            Models.Like theLike = db.Likes.SingleOrDefault(c => c.person_id == personId && c.picture_id == id);

            Models.Picture thePerson = db.Pictures.SingleOrDefault(c => c.picture_id == theLike.picture_id);

            db.Likes.Remove(theLike);
            db.SaveChanges();

            return(RedirectToAction("Index", new { id = thePerson.person_id }));
        }
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            // check user is authorized
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            // attempt to get like from repo
            var like = await _repo.GetLike(id, recipientId);

            // if exists the repo already has a like for that user
            if (like != null)
            {
                return(BadRequest("You've already liked this user"));
            }

            // user cannot like themselves
            if (id == recipientId)
            {
                return(BadRequest("You cannot like yourself"));
            }

            // if the user being liked doesn't exist return not found
            if (await _repo.GetUser(recipientId, false) == null)
            {
                return(NotFound());
            }

            // create a new like object
            like = new Models.Like
            {
                LikerId = id,
                LikeeId = recipientId
            };

            // pass the new like into the repo
            _repo.Add <Like>(like);

            // attempt to save the new like into the repo
            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user"));
        }
        public ActionResult LikePic(int id)
        {
            int personId = Int32.Parse(Session["person_id"].ToString());

            Models.Like newLike = new Models.Like()
            {
                person_id  = personId,
                picture_id = id,
                timestamp  = DateTime.Now.ToString(),
                read       = "Not read"
            };

            Models.Picture thePerson = db.Pictures.SingleOrDefault(c => c.picture_id == newLike.picture_id);

            db.Likes.Add(newLike);
            db.SaveChanges();

            ViewBag.liked = db.Likes.SingleOrDefault(c => c.person_id == personId && c.picture_id == id);

            return(RedirectToAction("Index", new { id = thePerson.person_id }));
        }
        public ActionResult LikePicture(int id)
        {
            // TODO: Add insert logic here
            int user_id = int.Parse(Session["user_id"].ToString());

            Models.Profile theProfile = database.Profiles.SingleOrDefault(p => p.user_id == user_id);
            Models.Picture thePicture = database.Pictures.SingleOrDefault(p => p.picture_id == id);

            Models.Like likePicture = new Models.Like()
            {
                picture_id = thePicture.picture_id,
                profile_id = theProfile.profile_id,
                timestamp  = DateTime.Now,
                read       = 0
            };

            database.Likes.Add(likePicture);
            database.SaveChanges();

            return(RedirectToAction("Index", new { id = thePicture.profile_id }));
        }
Exemple #13
0
        public async Task <IActionResult> GetLike(int userId, int recieverId)
        {
            var currentUserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (userId != currentUserId)
            {
                return(Unauthorized());
            }

            var like = await dataContext.GetLikeAsync(userId, recieverId);

            if (like != null)
            {
                return(BadRequest("You've already liked this user"));
            }

            if (await dataContext.GetUserAsync(recieverId) == null)
            {
                return(NotFound());
            }

            like = new Models.Like()
            {
                LikeeId = userId,
                LikerId = recieverId
            };

            dataContext.AddAsync <Like>(like);

            if (await dataContext.SaveAllAsync())
            {
                return(Ok());
            }

            else
            {
                return(BadRequest("Something went wrong"));
            }
        }
        /// <summary>
        /// Performs like or dislike action on an image
        /// </summary>
        /// <param name="LikeModel">Like model</param>
        /// <param name="imageId">Image key</param>
        /// <param name="like">User input: 1-Like; 0-Dislike </param>
        /// <returns>Json with success or failure response</returns>
        public ActionResult Like(Models.Like LikeModel, string imageId, string like)
        {
            int  UserId  = Int32.Parse(Session["UserId"].ToString());
            int  ImageId = Int32.Parse(imageId);
            bool Like    = like == "1";

            LikeModel.SetLike(UserId, ImageId, Like);
            ViewBag.Like = Like;

            string Message = "You have disliked this image.";

            if (Like)
            {
                Message = "You have liked this image.";
            }

            // TODO: Handle errors and returned failure message.

            return(Json(new
            {
                Success = true,
                Message = Message
            }, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
        public async Task <IActionResult> LikeUser(int id, int recipientId)
        {
            // check authorization
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var like = await _repository.GetLike(id, recipientId);

            if (like != null)
            {
                return(BadRequest("You already liked this user"));
            }

            if (await _repository.GetUser(recipientId) == null)
            {
                return(NotFound());
            }

            // create model and save it to the repository
            like = new Models.Like
            {
                LikerId = id,
                LikeeId = recipientId
            };

            _repository.Add(like);

            if (await _repository.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to like user"));
        }
Exemple #16
0
 public int Create(Models.Like like)
 {
     this.dbContext.Likes.Add(like);
     this.dbContext.SaveChanges();
     return(like.Id);
 }