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; }
public List<API_User> GetAllUsers() { var rcUsrs = new List<API_User>(); var rc = _dataAccess.User_GetAllUsers(); if (rc == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } else { var apiUsr = new API_User(); foreach (var usr in rc) { rcUsrs.Add(apiUsr.ConvertToAPI_UserWithoutAssociatedLists(usr)); } } return rcUsrs; }
/// <summary> /// NOTE: THIS WAS ALL AUTO-GENED BY VS2012 /// </summary> // GET api/ListShare public IQueryable<API_ListShare>GetListShares() { API_ListShare converter = new API_ListShare(); var rcListShares = new List<API_ListShare>(); using (var dataMethods = new Data.DataMethods()) { var listshares = dataMethods.ListShare_GetAll(); if (listshares != null) { foreach (var s in listshares) { var newItem = converter.ConvertToAPI_ListShareWithAssociatedList(s); rcListShares.Add(newItem); } } } return rcListShares.AsQueryable(); }
// GET api/ListItem/GetItems public List<API_ListItem> GetItems() { List<API_ListItem> returnItems = new List<API_ListItem>(); try { using (_dataMethods = new DataMethods()) { var listItems = _dataMethods.ListItem_GetAll(); foreach (var i in listItems) { returnItems.Add(converter.ConvertToAPI_ListItem(i,i.List.PublicKey)); } } } catch (Exception) { throw; } return returnItems; }
/// <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; }
/// <summary> /// This method converts a List to an API_List object. /// </summary> /// <param name="list"></param> /// <returns></returns> public API_List ConvertToAPI_ListWithAllItems(List list) { var rcList = _CreateShellList(list); try { if ((rcList != null) && (list.Items != null) && (list.Items.Count > 0)) { API_ListItem apiListItem = new API_ListItem(); foreach (var i in list.Items.OrderBy(li => li.Ordinal)) { rcList.Items.Add(apiListItem.ConvertToAPI_ListItem(i, rcList.PublicKey)); } } } catch (ObjectDisposedException) { } return rcList; }
public IQueryable<API_ListItem> GetItemsForList(string id) { var rcListItem = new List<API_ListItem>(); if (id != string.Empty) { using (_dataMethods = new DataMethods()) { var list = _dataMethods.List_GetListByPublicKey(id); if (list == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } else { // Convert each ListItem to an API_ListItem foreach (var i in list.Items) { rcListItem.Add(converter.ConvertToAPI_ListItem(i, id)); } } } } else { throw new HttpException("List Public Key not Provided!"); } return rcListItem.AsQueryable(); }
/// <summary> /// Creates a new Gyfto List /// </summary> /// <param name="listTitle"></param> /// <param name="listDescription"></param> /// <param name="userPublicKey"></param> /// <returns></returns> public List List_CreateList(string listTitle, string listDescription, string userPublicKey) { List newList = new List(); try { newList.Active = true; newList.CreateDate = DateTime.Now; newList.Description = listDescription; newList.Title = listTitle; newList.User = User_GetUser(userPublicKey); newList.PublicKey = GeneratePublicKey(); _gyftoListEntities.Lists.AddObject(newList); _gyftoListEntities.SaveChanges(); } catch (Exception ex) { throw ex; } return newList; }
/// <summary> /// Deprecated Method for adding a new object to the Lists EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToLists(List list) { base.AddObject("Lists", list); }
public List<User> ListItem_GetAllConsumersByListItemPublicKey(string listItemPublicKey) { var rcUsers = new List<User>(); using (_gyftoListEntities = new GyftoListEntities()) { // First, get the list of all the consumers for the List this Item is associated to var currentItem = ListItem_GetByPublicKey(listItemPublicKey); var listConsumers = ListShare_GetCoConsumersForListShare(currentItem.List.PublicKey); // Cache all the Item Exclusions var itemExclusions = ItemExclusion_GetByItemPublicKey(listItemPublicKey); // Next, weed out any Item Exclusions foreach (var ls in ListShare_GetAllByListItemPublicKey(listItemPublicKey)) { if (itemExclusions.Where(ie => ie.ListShareID == ls.ListShareID && ie.ItemID == currentItem.ItemID).Count() == 0) { rcUsers.Add(ls.UserConsumer); } } } return rcUsers; }
/// <summary> /// This returns all the Items for a given List /// </summary> /// <param name="listID">Internal List ID</param> /// <param name="onlyActive">True = only get Active items</param> /// <returns></returns> public List<Item> ListItem_GetAllByListID(int listID, bool onlyActive) { var rcItems = new List<Item>(); if (onlyActive) { rcItems = _gyftoListEntities.Items.Where(i => i.ListID == listID && i.Active == true).ToList(); } else { rcItems = _gyftoListEntities.Items.Where(i => i.ListID == listID).ToList(); } return rcItems; }
/// <summary> /// This returns all Items within Gyfto /// </summary> /// <returns></returns> public List<Item> ListItem_GetAll() { List<Item> rcListItems = new List<Item>(); try { rcListItems = _gyftoListEntities.Items.Where(i => i.Active == true).ToList(); } catch (Exception) { throw; } return rcListItems; }
/// <summary> /// Gets an Item Exclusion by it's associated Item /// </summary> /// <param name="itemPublicKey"></param> /// <returns></returns> public List<ItemExclusion> ItemExclusion_GetByItemPublicKey(string itemPublicKey) { var rc = new List<ItemExclusion>(); try { var item = ListItem_GetByPublicKey(itemPublicKey); if (item != null) { rc = _gyftoListEntities.ItemExclusions.Where(i => i.ItemID == item.ItemID).ToList(); } else { throw new Exception(string.Format("Unable to get Item with Public Key '{0}'", itemPublicKey)); } } catch (Exception) { throw; } return rc; }
/// <summary> /// Return a collection of List Item Exclusions by List Share Public Key /// </summary> /// <param name="publicKey">List Share Public Key</param> /// <returns></returns> public List<ItemExclusion> ItemExclusion_GetAllByListShare(string publicKey) { //TODO: Test by attempting to get all the Item Exclusions for a know List Share var rcItemExclusions = new List<ItemExclusion>(); //Get the List Share, then iterate across all the Items and then all the associated Item Exclusions var listShare = ListShare_GetByPublicKeyWithAssociatedItems(publicKey); return _gyftoListEntities.ItemExclusions.Where(i => i.ListShareID == listShare.ListShareID).ToList(); }
/// <summary> /// Returns a list of Gyfto Users /// </summary> /// <returns></returns> public List<User> User_GetAllUsers() { //return _gyftoListEntities.Users; List<User> returnUsers = new List<User>(); try { //using (_gyftoListEntities = new GyftoListEntities()) //{ foreach (var usr in _gyftoListEntities.Users) { returnUsers.Add(usr); } //} } catch (Exception ex) { throw new Exception(string.Format("Unable to return list of All Users - Error: '{0}'", ex.InnerException.ToString())); } return returnUsers; }
/// <summary> /// Create a new List object. /// </summary> /// <param name="listID">Initial value of the ListID property.</param> /// <param name="createDate">Initial value of the CreateDate property.</param> public static List CreateList(global::System.Int32 listID, global::System.DateTime createDate) { List list = new List(); list.ListID = listID; list.CreateDate = createDate; return list; }
/// <summary> /// Gets all the ListShares for a specific List /// </summary> /// <param name="listPublicKey"></param> /// <returns></returns> public List<ListShare> ListShare_GetAllByListPublicKey(string listPublicKey) { var rcListShare = new List<ListShare>(); //using (_gyftoListEntities = new GyftoListEntities()) //{ List usrList = _gyftoListEntities.Lists.SingleOrDefault(l => l.PublicKey == listPublicKey); rcListShare = _gyftoListEntities.ListShares.Where(ls => ls.ListID == usrList.ListID).ToList(); //} return rcListShare; }
/// <summary> /// Gets all the ListShares for a particular User/Owner by their PublicKey /// </summary> /// <param name="ownerPublicKey"></param> /// <returns></returns> public List<ListShare> ListShare_GetAllListSharesForOwner(string ownerPublicKey) { List<ListShare> listShares = new List<ListShare>(); User usrOwner = _gyftoListEntities.Users.Where(c => c.PublicKey == ownerPublicKey).First(); listShares = _gyftoListEntities.ListShares.Where(ls => ls.OwnerID == usrOwner.UserID).ToList(); return listShares; }
/// <summary> /// Returns all Consumers of List Shares for a base List /// </summary> /// <param name="listPublicKey"></param> /// <returns></returns> public List<User> ListShare_GetCoConsumersForListShare(string listPublicKey) { var rcUsers = new List<User>(); try { // Get the base list foreach (var ls in ListShare_GetAllByListPublicKey(listPublicKey)) { rcUsers.Add(ls.UserConsumer); } } catch (Exception ex) { throw new Exception(string.Format("Unable to located Co-Consumers for this List Share - '{0}'",ex.InnerException.ToString())); } return rcUsers; }