Exemple #1
0
        /// <summary>
        /// Gets a User by PublicKey
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public API_User GetSpecificUser(string id)
        {
            var usr = _dataAccess.User_GetUser(id);
            if (usr == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            // API_User object
            var apiUser = new API_User();
            apiUser = apiUser.ConvertToAPI_UserWithAssociatedLists(usr);

            var apiListShare = new API_ListShare();
            // Get ListShares they own
            foreach (var ols in _dataAccess.ListShare_GetAllListSharesForOwner(apiUser.PublicKey))
            {
                apiUser.OwnedListShares.Add(apiListShare.ConvertToAPI_ListShareWithoutAssociatedList(ols));
            }

            // Get ListShares they consume
            foreach (var cls in _dataAccess.ListShare_GetAllListSharesForConsumer(apiUser.PublicKey))
            {
                apiUser.ConsumedListShares.Add(apiListShare.ConvertToAPI_ListShareWithoutAssociatedList(cls));
            }

            return apiUser;
        }
Exemple #2
0
 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;
 }
Exemple #3
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;
        }
Exemple #4
0
        /// <summary>
        /// Creates the shell User object
        /// </summary>
        /// <param name="usr"></param>
        /// <returns></returns>
        private API_User GetShellUserObject(User usr)
        {
            var apiUsr =  new API_User { FName = usr.FName, LName = usr.LName, PublicKey = usr.PublicKey, AvatarURL = usr.AvatarURL };
            if ((usr.FName == string.Empty) && (usr.LName == string.Empty))
            {
                if (usr.EmailAddresses.Where(e => e.IsDefault == true).Count() != 1)
                {
                    apiUsr.DisplayName = "Unknown User";
                }
                else
                {
                    apiUsr.DisplayName = usr.EmailAddresses.SingleOrDefault(e => e.IsDefault == true).EmailAddress1;
                }
            }
            else
            {
                apiUsr.DisplayName = string.Format("{0} {1}", usr.FName, usr.LName.Substring(0, 1));
            }

            return apiUsr;
        }
        // GET api/ListShare/5
        public API_ListShare GetListShare(string id)
        {
            API_ListShare rShare = new API_ListShare();

            if (!string.IsNullOrEmpty(id))
            {
                using (var dataMethods = new Data.DataMethods())
                {
                    var listShare = dataMethods.ListShare_GetByPublicKeyWithAssociatedItems(id);
                    if (listShare == null)
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
                    }
                    else
                    {
                        // Convert the ListShare to the public API_ListShare format
                        rShare = rShare.ConvertToAPI_ListShareWithAssociatedList(listShare);

                        // Next, get all the co-consumers of this list
                        foreach (var usr in dataMethods.ListShare_GetCoConsumersForListShare(listShare.List.PublicKey))
                        {
                            rShare.CoConsumers.Add(new API_User()
                            {
                                FName = usr.FName
                                ,
                                LName = usr.LName
                                ,
                                AvatarURL = usr.AvatarURL
                                ,
                                PublicKey = usr.PublicKey
                                ,
                                DisplayName = string.Concat(usr.FName, " ", usr.LName.Substring(0,1))
                            });
                        }

                        // Last, for each Item - get any Co-Consumers there as well
                        var convertUser = new API_User();
                        //foreach (var item in rShare.SharedList.Items)
                        //{
                        //    foreach (var usr in dataMethods.ListItem_GetAllConsumersByListItemPublicKey(item.PublicKey))
                        //    {
                        //        item.CoConsumer.Add(convertUser.ConvertToAPI_UserWithoutAssociatedLists(usr));
                        //    }
                        //}
                    }
                }
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return rShare;
        }