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; }
/// <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; }
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); }
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; }
/// <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; }
/// <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; }
/// <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; }
/// <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; }
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; }