Exemple #1
0
        public IEnumerable <Item> Get(Guid?identifier = null, string s = null, string key = null)
        {
            var callerId = User.IdentifierSafe();

            if ((identifier.HasValue && Guid.Empty != identifier.Value) ||
                !string.IsNullOrWhiteSpace(key))
            {
                var list = new List <Item>(1);
                list.Add(itemCore.GetItem(identifier, key, callerId));
                return(list);
            }
            else
            {
                return(itemCore.Search(null, s, null, null, callerId));
            }
        }
Exemple #2
0
        //
        // GET: /item/{Key}
        public ActionResult Unique(Guid?id = null, string key = null)
        {
            if (!id.HasValue && string.IsNullOrWhiteSpace(key))
            {
                return(RedirectToAction("Index"));
            }

            var callerId = User.IdentifierSafe();

            var master = new ItemMaster()
            {
                Display = itemCore.GetItem(id, key, callerId),
            };

            if (null != master.Display)
            {
                master.Display.SetCategories();
                var dic = new Dictionary <Guid, ItemShare>();
                foreach (var s in from s in borrowCore.Shares(master.Display)
                         where s.Status == BorrowStatus.Returned
                         select s)
                {
                    if (!dic.ContainsKey(s.RequesterUserIdentifier))
                    {
                        dic.Add(s.RequesterUserIdentifier, s);
                    }
                }
                master.Display.Shares = dic.Values;

                var relatedProductQuery = string.Empty;
                if (null != master.Display.Categories &&
                    0 < master.Display.Categories.Count())
                {
                    relatedProductQuery = string.Join(" ", master.Display.Categories);
                    relatedProductQuery.Replace('#', (char)0);
                }
                else if (!string.IsNullOrWhiteSpace(master.Display.Title))
                {
                    relatedProductQuery = master.Display.Title;
                }

                if (!string.IsNullOrWhiteSpace(relatedProductQuery))
                {
                    master.Results = from i in this.luceneCore.Search(relatedProductQuery, callerId, 6, Reference.Item)
                                     where i.Key != key
                                     select i;
                }

                if (null != master.Display.Categories &&
                    (from c in master.Display.Categories where c.ToLower() == "book" || c.ToLower() == "books" select c).Count() > 0)
                {
                    master.Display.ExternalReviews = this.goodReadsCore.GetReviewToken(master.Display.Title);
                }

                return(View(master));
            }
            else if (!string.IsNullOrWhiteSpace(key))
            {
                return(Redirect(ItemCore.SearchUrl(key, "unknown_key")));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }