예제 #1
0
        public HttpResponseMessage getPlaceList()
        {
            var intList = db.placeLists.Select(p => p.id).ToList();

            int[] placeListArray = intList.ToArray();
            Array.Sort(placeListArray);
            List <queryPlaceList> placesList = new List <queryPlaceList>();

            foreach (int i in placeListArray)
            {
                //var placeListItem = db.placeLists.AsEnumerable().FirstOrDefault(p => p.id == i);
                //var userListItem = db.users.AsEnumerable().FirstOrDefault(u => u.id == placeListItem.id);
                var            placeListItem = db.placeLists.FirstOrDefault(p => p.id == i);
                var            userListItem  = db.users.FirstOrDefault(u => u.id == placeListItem.user_id);
                queryPlaceList listItem      = new queryPlaceList();
                listItem.id          = placeListItem.id;
                listItem.listName    = placeListItem.name;
                listItem.description = placeListItem.description;
                listItem.privacy     = placeListItem.privacy;
                listItem.user_id     = placeListItem.user_id;
                listItem.user_name   = userListItem.name;
                listItem.createdTime = placeListItem.created.ToString();
                listItem.updatedTime = placeListItem.updated.ToString();
                placesList.Add(listItem);
            }
            var result = new
            {
                data  = placesList,
                total = placesList.Count()
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
예제 #2
0
        public HttpResponseMessage getPlaceList()
        {
            var intList = db.placeLists.Select(p => p.id).ToList();

            int[] placeListArray = intList.ToArray();
            int   responseId     = 0;

            Array.Sort(placeListArray);
            List <queryPlaceList> placesList = new List <queryPlaceList>();

            foreach (int i in placeListArray)
            {
                responseId++;
                //var placeListItem = db.placeLists.AsEnumerable().FirstOrDefault(p => p.id == i);
                //var userListItem = db.users.AsEnumerable().FirstOrDefault(u => u.id == placeListItem.id);
                var   intPlaceRelation = db.placeRelationships.Where(p => p.placelist_id == i).Select(p => p.place_id).ToList();
                int[] placeIdArray     = intPlaceRelation.ToArray();
                Array.Sort(placeIdArray);
                List <placeTimelineItem> placeTimelineList = new List <placeTimelineItem>();
                foreach (int j in placeIdArray)
                {
                    var placeModel              = db.places.Where(p => p.id == j).FirstOrDefault();
                    var placeRelationModel      = db.placeRelationships.Where(p => p.place_id == j && p.placelist_id == i).FirstOrDefault();
                    placeTimelineItem placeItem = new placeTimelineItem();
                    placeItem.placeName   = placeModel.name;
                    placeItem.createdTime = placeRelationModel.created.ToString();
                    placeItem.icon        = "el-icon-place";
                    placeItem.size        = "large";
                    placeItem.type        = "success";
                    placeTimelineList.Add(placeItem);
                }
                var            placeListItem = db.placeLists.FirstOrDefault(p => p.id == i);
                var            userListItem  = db.users.FirstOrDefault(u => u.id == placeListItem.user_id);
                queryPlaceList listItem      = new queryPlaceList();
                listItem.id            = responseId;
                listItem.list_id       = i;
                listItem.listName      = placeListItem.name;
                listItem.description   = placeListItem.description;
                listItem.privacy       = placeListItem.privacy;
                listItem.user_id       = placeListItem.user_id;
                listItem.user_name     = userListItem.name;
                listItem.createdTime   = placeListItem.created.ToString();
                listItem.updatedTime   = placeListItem.updated.ToString();
                listItem.timelineItmes = placeTimelineList;
                placesList.Add(listItem);
            }
            var result = new
            {
                data  = placesList,
                total = placesList.Count()
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
예제 #3
0
        public HttpResponseMessage updatePlaceList(queryPlaceList updateItem)
        {
            var placeListItem = db.placeLists.FirstOrDefault(p => p.id == updateItem.list_id);
            var userListItem  = db.users.FirstOrDefault(u => u.id == updateItem.user_id);

            placeListItem.name        = updateItem.listName;
            placeListItem.description = updateItem.description;
            placeListItem.privacy     = updateItem.privacy;
            placeListItem.updated     = DateTime.Now;
            //placeListItem.cover = updateItem.cover;
            userListItem.name = updateItem.user_name;
            db.SaveChanges();
            var result = new
            {
                msg = "success"
            };

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }