示例#1
0
        public async Task <IActionResult> Like(Yorum model)
        {
            var user = await userManager.GetUserAsync(User);

            UserLikes like = new UserLikes();

            like.YorumId = model.Id;
            like.UserId  = user.Id;


            var SearchData = _context.UserLikes.AsNoTracking().Where(y => y.YorumId == model.Id && y.UserId == user.Id).SingleOrDefault();

            if (SearchData != null)
            {
                await _userService.Unlike(like);
            }
            else
            {
                await _userService.Like(like);
            }



            return(RedirectToAction("Index", "Yorums"));
        }
        public JsonResult GetResults(UserLikes model)
        {
            model.Choose = new JavaScriptSerializer().Deserialize <int[]>(Request["Choose"]);
            model.Shown  = new JavaScriptSerializer().Deserialize <List <int> >(Request["Shown"]);
            model.Vector = new JavaScriptSerializer().Deserialize <int[]>(Request["Vector"]);

            var service = new TravelService.TravelServiceClient();

            try
            {
                service.Open();
                var numbers = service.GetResults(model.Choose, model.Shown.ToArray());
                for (var i = 0; i < 4; i++)
                {
                    model.Vector[i] = (model.Vector[i] + numbers[i]) / 3;
                }

                var result = service.GetIntrest(model.Vector);
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#3
0
        public string fileString()
        {
            string result = "";

            for (int i = 0; i < UserLikes.Count(); i++)
            {
                if (i < UserLikes.Count() - 1)
                {
                    result = result + UserLikes[i] + "+";
                }
                else
                {
                    result += UserLikes[i];
                }
            }
            result += ",";
            for (int i = 0; i < UserDislikes.Count(); i++)
            {
                if (i < UserDislikes.Count() - 1)
                {
                    result += UserDislikes[i] + "+";
                }
                else
                {
                    result += UserDislikes[i];
                }
            }

            return(result);
        }
        public async Task <ActionResult> AddLike(string username)
        {
            var userId = User.GetUserId();
            var user   = await _mainRepositories.UserLikesRespository.GetUserWithLikes(userId);

            var likedUser = await _mainRepositories.AppUserRespository.GetUserByUserNameAsync(username);

            if (likedUser == null)
            {
                return(NotFound());
            }
            if (likedUser.Id == userId)
            {
                return(BadRequest("You cannot like yourself."));
            }
            if (user.LikedUsers.Any(x => x.likedUserId == likedUser.Id))
            {
                return(BadRequest("Person was liked."));
            }

            var userlikes = new UserLikes
            {
                likedByUserId = userId,
                likedUserId   = likedUser.Id
            };

            user.LikedUsers.Add(userlikes);
            if (!await _mainRepositories.Complete())
            {
                return(BadRequest("Fail to add likes"));
            }
            return(Ok());
        }
示例#5
0
        public async Task OnPostConfirmerAsync(string id)
        {
            try {
                var userSelected = (from u in await _context.AspNetUsers.ToListAsync()
                                    where u.Email.Equals(id)
                                    select new UserViewModel {
                    UserName = u.UserName, Age = DateTime.Now.Year - u.Birthday.Year
                })
                                   .FirstOrDefault();
                SearchUser = userSelected;

                string searchUserId = (from u in await _context.AspNetUsers.ToListAsync()
                                       where u.Email.Equals(id)
                                       select u.Id).FirstOrDefault();
                string currentUserId = _userManager.GetUserId(User);

                UserLikes usersMatch = new UserLikes {
                    Id = currentUserId, Id1 = searchUserId
                };
                _context.UserLikes.Add(usersMatch);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                Error = "Vous avez déjà liker ce profil";
            }
        }
示例#6
0
        public async Task <IActionResult> PutUserLikes([FromRoute] int id, [FromBody] UserLikes userLikes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userLikes.ID)
            {
                return(BadRequest());
            }

            _context.Entry(userLikes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserLikesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public static void insertUserLikes(UserLikes userLike)
 {
     using (var entity = new EntityFramework.CheckinDatasetEntities4())
     {
         entity.UserLikes.Add(userLike);
         entity.SaveChanges();
     }
 }
 public static void deleteUserLikes(UserLikes userLike)
 {
     using (var entity = new EntityFramework.CheckinDatasetEntities4())
     {
         entity.UserLikes.Remove(userLike);
         entity.SaveChanges();
     }
 }
示例#9
0
        //记录用户的推荐操作
        /// <summary>
        /// 记录用户的推荐操作
        /// </summary>
        /// <param name="u_id">用户ID</param>
        /// <param name="target_id">操作对象ID</param>
        /// <param name="type_id">操作对象类型</param>
        /// <returns></returns>
        public static bool Recommend(int u_id, int target_id, int type_id)
        {
            UserLikes data = new UserLikes()
            {
                User_ID = u_id, UL_Type = type_id, UL_Target = target_id, UL_Time = DateTime.Now
            };

            db.UserLikes.Add(data);
            return(db.SaveChanges() > 0 ? true : false);
        }
        public static UserLikes getUserLikes(int userLikeID)
        {
            UserLikes uLike = new UserLikes();

            using (var entity = new EntityFramework.CheckinDatasetEntities4())
            {
                uLike = entity.UserLikes.ToList().Find(l => l.USERLIKEID == userLikeID);
            }
            return(uLike);
        }
示例#11
0
        public async Task <IActionResult> PostUserLikes([FromBody] UserLikes userLikes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.UserLikes.Add(userLikes);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUserLikes", new { id = userLikes.ID }, userLikes));
        }
示例#12
0
 public ActionResult Post([FromBody] UserLikes value)
 {
     Dse.ISession session = SessionManager.GetSession();
     if (session != null)
     {
         Row hasLiked = session.Execute("select count(*), username, \"newsID\", \"isLike\" from \"UserLikes\" where username = '******' and \"newsID\" =" + "'" + value.NewsID + "'").FirstOrDefault();
         if (Int32.Parse(hasLiked["count"].ToString()) == 0)
         {
             session.Execute("insert into \"UserLikes\"(\"username\", \"newsID\", \"isLike\") values('" + value.Username + "', '" + value.NewsID + "', " + value.IsLike + ")");
             if (value.IsLike)
             {
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"News\" set dislikes = " + (value.NumberOfDislikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
         else if (value.IsLike)
         {
             if (Boolean.Parse(hasLiked["isLike"].ToString()))
             {
                 session.Execute("delete from \"UserLikes\" where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"UserLikes\" set \"isLike\" = " + true + " where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes + 1) + ", dislikes = " + (value.NumberOfDislikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
         else if (!value.IsLike)
         {
             if (!Boolean.Parse(hasLiked["isLike"].ToString()))
             {
                 session.Execute("delete from \"UserLikes\" where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set dislikes = " + (value.NumberOfDislikes - 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
             else
             {
                 session.Execute("update \"OnlineNews\".\"UserLikes\" set \"isLike\" = " + false + " where username = '******' and \"newsID\" ='" + value.NewsID + "'");
                 session.Execute("update \"OnlineNews\".\"News\" set likes = " + (value.NumberOfLikes - 1) + ", dislikes = " + (value.NumberOfDislikes + 1) + " where \"newsID\" = '" + value.NewsID + "'");
                 return(StatusCode(200));
             }
         }
     }
     return(StatusCode(500));
 }
示例#13
0
 public async Task <IActionResult> checkUserLikesMessge([Required] User_Like_Message userLikeMessage)
 {
     return(await Wrapper.wrap(async (OracleConnection conn) =>
     {
         RestfulResult.RestfulData <UserLikes> rr = new RestfulResult.RestfulData <UserLikes>();
         rr.Code = 200;
         UserLikes l = new UserLikes();
         l.like = await checkUserLikesMessageBool(userLikeMessage.user_id, userLikeMessage.message_id);
         rr.Data = l;
         rr.Message = "success";
         return new JsonResult(rr);
     }));
 }
示例#14
0
        public bool Postlike(Likes like)
        {
            var n = (from e in db.Users
                     where e.UserName == like.userName
                     select e.Id).FirstOrDefault();
            var q = (from i in db.UserLikes
                     where i.PostId == like.postId &&
                     i.UserID == n
                     select i).FirstOrDefault();

            if (q == null)
            {
                UserLikes likes = new UserLikes();
                likes.PostId = like.postId;
                likes.UserID = n;
                likes.Status = true;
                db.UserLikes.Add(likes);
                var l = (from k in db.posts
                         where k.ID == like.postId
                         select k).FirstOrDefault();
                l.Likes += 1;
                db.SaveChanges();
            }
            else
            {
                if (q.Status == false)
                {
                    q.Status = true;
                    var l = (from k in db.posts
                             where k.ID == like.postId
                             select k).FirstOrDefault();
                    l.Likes += 1;
                    db.SaveChanges();
                }
                else
                {
                    q.Status = false;
                    var l = (from k in db.posts
                             where k.ID == like.postId
                             select k).FirstOrDefault();
                    l.Likes -= 1;
                    db.SaveChanges();
                }
            }
            return(true);
        }
示例#15
0
 public static void birPuanEkle(int[] dizi, int id)
 {
     using (CheckinDatasetEntities4 db = new CheckinDatasetEntities4())
     {
         if (dizi.Count() > 1)
         {
             foreach (int deger in dizi)
             {
                 UserLikes yeni = new UserLikes()
                 {
                     USERLOGINID = id,
                     LIKEID      = deger,
                     VALUE       = 1
                 };
                 db.UserLikes.Add(yeni);
                 db.SaveChanges();
             }
         }
     }
 }
示例#16
0
        public async Task OnPostConfirmerAsync(string id)
        {
            try
            {
                string searchUserId = (from u in await _context.AspNetUsers.ToListAsync()
                                       where u.Email.Equals(id)
                                       select u.Id).FirstOrDefault();
                string currentUserId = _userManager.GetUserId(User);

                UserLikes usersMatch = (from us in await _context.UserLikes.ToListAsync()
                                        where us.Id.Equals(currentUserId) && us.Id1.Equals(searchUserId)
                                        select us).FirstOrDefault();
                _context.UserLikes.Remove(usersMatch);
                _context.SaveChanges();
            }
            catch (Exception)
            {
                Error = "Vous n'avez pas liker ce profil";
            }
        }
        public async Task Like(int commentId, ApplicationUser user)
        {
            var comment = this.commentRepo.All().FirstOrDefault(x => x.Id == commentId);

            if (comment == null)
            {
                throw new ArgumentNullException("Not existing comment with given id.");
            }

            // TODO:
            var like = new UserLikes()
            {
                Comment   = comment,
                CommentId = commentId,
                User      = user,
                UserId    = user.Id,
            };

            comment.UserLikes.Add(like);

            await this.commentRepo.SaveChangesAsync();
        }
        public JsonResult GetOptions(UserLikes model)
        {
            model.Choose = new JavaScriptSerializer().Deserialize <int[]>(Request["Choose"]);
            model.Shown  = new JavaScriptSerializer().Deserialize <List <int> >(Request["Shown"]);
            model.Vector = new JavaScriptSerializer().Deserialize <int[]>(Request["Vector"]);


            var service = new TravelService.TravelServiceClient();

            try
            {
                service.Open();
                var factory = new ImageLikeFactory();
                var list    = new List <LikeOption>();
                var result  = service.GetOptions(model.Choose, model.Shown.ToArray());

                for (var i = 0; i < 9; i++)
                {
                    model.Shown.Add(result[0][i]);
                    list.Add(new LikeOption()
                    {
                        Id = result[0][i], Image = factory.Dictionary[result[0][i]], IsChecked = false
                    });
                }

                for (var i = 0; i < 4; i++)
                {
                    model.Vector[i] += result[1][i];
                }
                model.Options = list.ToArray();
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
示例#19
0
        public object Get(string username)
        {
            Dse.ISession     session         = SessionManager.GetSession();
            List <UserLikes> listOfNewsLiked = new List <UserLikes>();

            if (session != null)
            {
                UserLikes tmp;
                var       rows = session.Execute("select * from \"UserLikes\" where username = '******'");
                if (rows != null)
                {
                    foreach (var row in rows)
                    {
                        tmp          = new UserLikes();
                        tmp.NewsID   = row["newsID"].ToString();
                        tmp.Username = row["username"].ToString();
                        tmp.IsLike   = Boolean.Parse(row["isLike"].ToString());
                        listOfNewsLiked.Add(tmp);
                    }
                }
            }
            return(listOfNewsLiked);
        }
 public UserLikes Insert(UserLikes userLikes)
 {
     return(this._repoUserLikes.Insert(userLikes));
 }
示例#21
0
 public async Task Like(UserLikes yorum)
 {
     _context.UserLikes.Add(yorum);
     await _context.SaveChangesAsync();
 }
示例#22
0
 public async Task Unlike(UserLikes yorum)
 {
     _context.UserLikes.Remove(yorum);
     await _context.SaveChangesAsync();
 }
示例#23
0
 public UserLikes Insert(UserLikes userLikes)
 {
     return(this._UserLikesBiz.Insert(userLikes));
 }