Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        // 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;
        }
Ejemplo n.º 3
0
        /// <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();
        }
Ejemplo 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;
        }
Ejemplo n.º 5
0
        //
        // GET: /Share/
        public ActionResult List(string id)
        {
            var sharedList = new API_ListShare();
            if (id != string.Empty)
            {
                var util = new GyftoList.Util.Greeting();
                ViewBag.Greeting = util.GetRandomGreeting();

                var gAPI = new ListShareController();
                try
                {
                    sharedList = gAPI.GetListShare(id);
                }
                catch (Exception ex)
                {
                    throw new Exception("Shared List not found" + ex.InnerException.ToString());
                }
            }
            else { throw new Exception("Shared  List not provided"); }

            return View(sharedList);
        }
Ejemplo n.º 6
0
 public ListShare ConvertFromAPI_ListShare(API_ListShare listShare)
 {
     using(var dataMethods = new DataMethods())
     {
         return new ListShare() {
             List = dataMethods.List_GetListByPublicKey(listShare.SharedList.PublicKey)
             ,UserConsumer = dataMethods.User_GetUser(listShare.ConsumerPublicKey)
             ,UserOwner = dataMethods.User_GetUser(listShare.OwnerPublicKey)
         };
     }
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        private static HttpResponseMessage CreateListShare(API_ListShare listShare)
        {
            HttpResponseMessage response = client.PostAsJsonAsync("api/ListShare/PostListShare", listShare).Result;
            if (!response.IsSuccessStatusCode)
            {
                throw new Exception("Error");
            }

            return response;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        // PUT api/ListShare/5
        // NOTE: Changed this from an input of int(listShare.Id) to string (listShare.PublickKey) - not sure
        // what the outcome will be.  TODO: Test This
        //public HttpResponseMessage PutListShare(string id, ListShare listshare)
        //{
        //    if (ModelState.IsValid && id == listshare.PublicKey)
        //    {
        //        db.ListShares.Attach(listshare);
        //        db.ObjectStateManager.ChangeObjectState(listshare, System.Data.EntityState.Modified);
        //        try
        //        {
        //            db.SaveChanges();
        //        }
        //        catch (DbUpdateConcurrencyException)
        //        {
        //            return Request.CreateResponse(HttpStatusCode.NotFound);
        //        }
        //        return Request.CreateResponse(HttpStatusCode.OK);
        //    }
        //    else
        //    {
        //        return Request.CreateResponse(HttpStatusCode.BadRequest);
        //    }
        //}
        // POST api/ListShare
        public HttpResponseMessage PostListShare(API_ListShare listshare)
        {
            if ((ModelState.IsValid) && ((listshare.ListPublicKey != string.Empty) && (listshare.ConsumerPublicKey != string.Empty)))
            {
                using (var dataMethods = new Data.DataMethods())
                {
                    var newListShare = dataMethods.ListShare_Create(listshare.ListPublicKey, listshare.ConsumerPublicKey);
                    API_ListShare converter = new API_ListShare();
                    listshare = converter.ConvertToAPI_ListShareWithAssociatedList(newListShare);
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, listshare);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = listshare.ListPublicKey }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }