Exemplo n.º 1
0
        public JsonResult SetFavoriteSession(GitHubItemWrapper GhItemWrapper)
        {
            bool result = false;
            var  FavRes = manager.SetFavoritesToSession(GhItemWrapper);

            if (FavRes != null)
            {
                result = true;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
 public void AddGHubItem(List <GitHubItem> data, GitHubItemWrapper _ghItemWrapper)
 {
     try
     {
         data.Add(new GitHubItem()
         {
             id         = _ghItemWrapper.GitHubItem.id,
             name       = _ghItemWrapper.GitHubItem.name,
             avatar_url = _ghItemWrapper.GitHubItem.avatar_url,
         });
     }
     catch (Exception ex)
     {
         Log.Write(ex.Message, "RequestManager.cs", "GitHubSearch", "AddGHubItem");
     }
 }
Exemplo n.º 3
0
        public List <GitHubItem> SetFavoritesToSession(GitHubItemWrapper _ghItemWrapper)
        {
            List <GitHubItem> data = null;

            try
            {
                if (_ghItemWrapper != null && _ghItemWrapper.GitHubItem != null)
                {
                    data = sessionService.Get <List <GitHubItem> >("myFavorites");
                    if (_ghItemWrapper.FavAction == FavoriteAction.AddTofavorites)
                    {
                        if (data != null)
                        {
                            AddGHubItem(data, _ghItemWrapper);
                        }
                        else
                        {
                            data = new List <GitHubItem>();
                            AddGHubItem(data, _ghItemWrapper);
                        }
                    }
                    else if (_ghItemWrapper.FavAction == FavoriteAction.RemoveFromFavorites)
                    {
                        if (data != null)
                        {
                            var favToRemove = data.SingleOrDefault(d => d.id == _ghItemWrapper.GitHubItem.id);
                            if (favToRemove.id != 0)
                            {
                                data.Remove(favToRemove);
                            }
                        }
                    }
                }
                if (data != null)
                {
                    sessionService.Set("myFavorites", data);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex.Message, "RequestManager.cs", "GitHubSearch", "SetFavoritesToSession");
            }

            return(data);
        }