Esempio n. 1
0
        public List<API_List> GetUserLists(string userPublicKey)
        {
            var rcList = new List<API_List>();
            try
            {
                //
                using (_dataAccess = new DataMethods())
                {
                    var usr = _dataAccess.User_GetUser(userPublicKey);
                    if (usr != null)
                    {
                        var converter = new API_List();
                        var usrLists = _dataAccess.List_GetListByUserID(usr.UserID);
                        foreach (var l in usrLists)
                        {
                            rcList.Add(converter.ConvertToAPI_ListWithAllItems(l));
                        }
                    }
                    else
                    {
                        throw new Exception("Unable to source User: " + userPublicKey);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return rcList;
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an List object with associated List Items from an API_List object
        /// </summary>
        /// <param name="inputList"></param>
        /// <returns></returns>
        public List ConvertFromAPI_List(API_List inputList)
        {
            // First get the base list
            var rcList = new List()
            {
                Description = inputList.Description
                ,
                PublicKey = inputList.PublicKey
                ,
                Title = inputList.ListName
            };

            // Next, add converted Items
            if (inputList.Items.Count > 0)
            {
                var apiListItem = new API_ListItem();
                foreach (var i in inputList.Items)
                {
                    rcList.Items.Add(apiListItem.ConvertFromAPI_ListItem(i));
                }
            }

            // Finally, add converted ListShares
            // TODO: ADD 'CONVERT FROM' FOR API_ListShare
            if (inputList.ListShares.Count > 0)
            {
                var apiListShare = new API_ListShare();
                foreach(var s in inputList.ListShares)
                {

                }
            }

            return rcList;
        }
Esempio n. 3
0
        public ActionResult Details(string id)
        {
            var gAPI = new GyftoList.API.Controllers.ListController();
            API_List usrList = new API_List();
            try
            {
                usrList = gAPI.GetList(id);
            }
            catch (Exception)
            {

                throw;
            }

            return View(usrList);
        }
Esempio n. 4
0
        public API_List GetList(string id)
        {
            var usrList = _dataAccess.List_GetListByPublicKey(id);
            API_List rcUsrList = new API_List(); ;
            API_ListShare listShare = new API_ListShare();
            if (usrList == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            else
            {
                rcUsrList = rcUsrList.ConvertToAPI_ListWithActiveItems(usrList);
            }

            // Add the associated ListShares
            foreach (var ls in _dataAccess.ListShare_GetAllByListPublicKey(id))
            {
                rcUsrList.ListShares.Add(listShare.ConvertToAPI_ListShareWithoutAssociatedList(ls));
            }

            return rcUsrList;
        }
Esempio n. 5
0
        /// <summary>
        /// This builds a base/shell API_ListShare object
        /// </summary>
        /// <param name="listShare"></param>
        /// <returns></returns>
        private API_ListShare GetShellListShare(ListShare listShare)
        {
            var apiShare = new API_ListShare();
            var apiUsr = new API_User();
            var apiList = new API_List();
            DataMethods _dataMethods = new DataMethods();
            var uConsumerObj = _dataMethods.User_GetUser(listShare.ConsumerID);
            var oConsumerObj = _dataMethods.User_GetUser(listShare.OwnerID);

            var uConsumer = apiUsr.ConvertToAPI_UserWithoutAssociatedLists(uConsumerObj);
            var uOwner = apiUsr.ConvertToAPI_UserWithoutAssociatedLists(oConsumerObj);

            apiShare.PublicKey = listShare.PublicKey;
            apiShare.ConsumerPublicKey = uConsumer.PublicKey;
            apiShare.OwnerPublicKey = uOwner.PublicKey;
            apiShare.ConsumerDisplayName = uConsumer.DisplayName;
            apiShare.OwnerDisplayName = uOwner.DisplayName;

            return apiShare;
        }
Esempio n. 6
0
        /// <summary>
        /// This will convert the internal ListShare to a API version with the associated List object
        /// </summary>
        /// <param name="listShare"></param>
        /// <returns></returns>
        public API_ListShare ConvertToAPI_ListShareWithoutAssociatedList(GyftoList.Data.ListShare listShare)
        {
            var apiShare = GetShellListShare(listShare);
            var apiList = new API_List();

            return apiShare;
        }
Esempio n. 7
0
        /// <summary>
        /// This will convert the internal ListShare to a API version with the associated List object
        /// </summary>
        /// <param name="listShare"></param>
        /// <returns></returns>
        public API_ListShare ConvertToAPI_ListShareWithAssociatedList(GyftoList.Data.ListShare listShare)
        {
            var apiShare = GetShellListShare(listShare);
            var apiList = new API_List();
            apiShare.SharedList = apiList.ConvertToAPI_ListWithAllItems(listShare.List);

            return apiShare;
        }
Esempio n. 8
0
        /// <summary>
        /// Converts User object to API_User objeect as well as any associated Lists they own
        /// </summary>
        /// <param name="usr"></param>
        /// <returns></returns>
        public API_User ConvertToAPI_UserWithAssociatedLists(User usr)
        {
            var apiUsr = GetShellUserObject(usr);

            // If Lists are there - convert them
            // TODO: This seems like a hack, not sure if there is a better way to handle this though
            try
            {
                if ((usr.Lists != null) && (usr.Lists.Count > 0))
                {
                    var apiList = new API_List();
                    foreach (var l in usr.Lists)
                    {
                        apiUsr.Lists.Add(apiList.ConvertToAPI_ListWithoutItems(l));
                    }
                }
            }
            catch (ObjectDisposedException) { }

            return apiUsr;
        }
Esempio n. 9
0
        private static List GetListByPublicKey(string listPublicKey)
        {
            var gyftoApi = new API_List();
            List translatedList = null;

            var requestURI = string.Format("api/List/GetList/{0}", listPublicKey);
            HttpResponseMessage response = client.GetAsync(requestURI.ToString()).Result;
            if (!response.IsSuccessStatusCode)
            {
                throw new Exception("Error");
            }
            else
            {
                translatedList = gyftoApi.ConvertFromAPI_List(response.Content.ReadAsAsync<API_List>().Result);
            }

            return translatedList;
        }