Exemplo n.º 1
0
        // This function gets the list of liked items for the specific user
        public async Task <List <LikeItem> > MakeLikeList()
        {
            // The list of integers
            List <int?> list = new List <int?>();
            // The list of likeitems
            List <LikeItem> LikeItemList = new List <LikeItem>();

            // Fill the list with list items nobody likes
            foreach (Item it in itemRepository.Items)
            {
                LikeItem Like = new LikeItem(it);
                LikeItemList.Add(Like);
            }

            // Now check if there is a user
            var name = HttpContext.User.Identity.Name;

            if (name != null)
            {
                var currentuser = await manager.FindByNameAsync(name).ConfigureAwait(false);

                // Get the id from this database
                var use = await userep.RetrieveByExternalAsync(currentuser.Id);

                list = await wishRepository.Wishes.Where(a => a.UserId == use.Id).Select(selector: b => b.ItemId).ToListAsync();

                // From this list got to the like items and change the items to liked
                // First check if list is empty ie the user has no favored any items if
                if (!list.Any())
                {
                    return(LikeItemList);
                }
                else
                {
                    foreach (int iid in list)
                    {
                        foreach (LikeItem litem in LikeItemList)
                        {
                            if (litem.BaseItem.Id == iid)
                            {
                                litem.IsLiked = true;
                            }
                        }
                    }
                    return(LikeItemList);
                }
            }
            else
            {
                return(LikeItemList);
            }
        }
        public object Create(object parent, object configContext, XmlNode section)
        {
            var list = section.SelectNodes("like");

            if (list == null || list.Count == 0)
            {
                return(null);
            }

            var li = new LikeItem[list.Count];

            for (var i = 0; i < li.Length; i++)
            {
                li[i] = new LikeItem((XmlElement)list[i]);
            }

            return(li);
        }
Exemplo n.º 3
0
        public ActionResult Like(int proId, int quantity, int curPage)
        {
            using (var ctx = new QLBHEntities())
            {
                var pro = ctx.Products
                          .Where(p => p.ProID == proId)
                          .FirstOrDefault();

                var item = new LikeItem
                {
                    Quantity = quantity,
                    idUser   = CurrentContext.GetCurUser().f_ID,
                    Product  = pro
                };

                CurrentContext.GetToLike().AddLikeItem(item);
                return(RedirectToAction("ByCat", "Product", new { id = pro.CatID, page = curPage }));
            }
        }