private static Tag CastTag(tTag linqTag) { return(linqTag == null ? null : new Tag { Id = linqTag.TagId, Text = linqTag.Text }); }
public HttpResponseMessage getHotTag() { int[] idList = db.tags.Select(t => t.id).ToArray(); string[] typeList = db.places.Select(p => p.type).Distinct().ToArray(); Array.Sort(idList); List <tTag> tagList = new List <tTag>(); userFactory.userEventRecord(0, 3, db); var tagInfo = new { system_tags = typeList, user_tags = tagList }; var result = new { status = 0, data = tagInfo, msg = "fail" }; if (idList.Count() > 0) { foreach (int i in idList) { var tagModel = db.tags.FirstOrDefault(t => t.id == i); tTag tagItem = new tTag(); tagItem.id = i; tagItem.name = tagModel.name; tagItem.type = tagModel.type; tagList.Add(tagItem); tagInfo = new { system_tags = typeList, user_tags = tagList }; result = new { status = 1, data = tagInfo, msg = "" }; } } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage getRecommendList(tFilter filter) { List <tPlaceList> placeList = new List <tPlaceList>(); List <int> intersectPlaceId = new List <int>(); List <int> intersectPlaceListId = new List <int>(); List <int> allPlaceId = new List <int>(); List <int> allTagIdInList = new List <int>(); int[] tagIdList = db.tags.Select(t => t.id).ToArray(); //string[] typeList = db.places.Select(p => p.type).Distinct().ToArray(); Array.Sort(tagIdList); List <tTag> tagList = new List <tTag>(); List <int> tagIDList = new List <int>(); List <string> typeList = new List <string>(); var tagInfo = new { lists = placeList, system_tags = typeList, user_tags = tagList }; var result = new { status = 1, data = tagInfo, msg = "" }; int userlogin = 0; userFactory.userEventRecord(userlogin, 1, db); var entirePlaces = db.places.Select(p => p.id).ToList(); var entirePlaceLists = db.placeLists.Select(p => p.id).ToList(); int filterCount = filter.filter.Length; intersectPlaceId = entirePlaces; intersectPlaceListId = entirePlaceLists; if (filterCount > 0) { foreach (int i in filter.filter) { intersectPlaceId = tagFactory.searchTag(userlogin, ref intersectPlaceId, i, db); } intersectPlaceId = intersectPlaceId.Distinct().ToList(); Array.Sort(intersectPlaceId.ToArray()); foreach (int i in intersectPlaceId) { var listFilter = db.placeRelationships.Where(p => p.place_id == i).Select(p => p.placelist_id).ToList(); tagIDList.AddRange(db.tagRelationships.Where(p => p.place_id == i).Select(q => q.tag_id).ToList()); intersectPlaceListId = intersectPlaceListId.Intersect(listFilter).ToList(); } tagIDList = tagIDList.Distinct().ToList(); Array.Sort(tagIDList.ToArray()); Array.Sort(intersectPlaceListId.Distinct().ToArray()); foreach (int i in intersectPlaceListId) { var placeListModel = db.placeLists.FirstOrDefault(p => p.id == i); tPlaceList placeListItem = new tPlaceList(); placeListItem.id = placeListModel.id; placeListItem.creator_id = placeListModel.user_id; placeListItem.name = placeListModel.name; //placeListItem.coverImageURL = placeListModel.cover; placeListItem.coverImageURL = placeListModel.cover != null ? placeListModel.cover : ""; placeList.Add(placeListItem); } if (tagIDList.Count > 0) { foreach (int i in tagIDList) { var tagModel = db.tags.FirstOrDefault(p => p.id == i && p.type == 2); if (tagModel != null) { tTag tagItem = new tTag(); tagItem.id = tagModel.id; tagItem.name = tagModel.name; tagItem.type = tagModel.type; tagList.Add(tagItem); } } } tagInfo = new { lists = placeList, system_tags = typeList, user_tags = tagList }; result = new { status = 1, data = tagInfo, msg = "" }; } else { foreach (int i in entirePlaceLists) { var placeListModel = db.placeLists.FirstOrDefault(p => p.id == i); if (placeListModel != null) { tPlaceList placeListItem = new tPlaceList(); placeListItem.id = placeListModel.id; placeListItem.creator_id = placeListModel.user_id; placeListItem.name = placeListModel.name; //placeListItem.coverImageURL = placeListModel.cover; placeListItem.coverImageURL = placeListModel.cover != null ? placeListModel.cover : ""; placeList.Add(placeListItem); } var placeInList = db.placeRelationships.Where(p => p.placelist_id == i).Select(q => q.place_id).ToList(); if (placeInList != null) { allPlaceId.AddRange(placeInList); } } allPlaceId = allPlaceId.Distinct().ToList(); if (allPlaceId.Count > 0) { foreach (int itemPlaceId in allPlaceId) { var tagInList = db.tagRelationships.Where(p => p.place_id == itemPlaceId).Select(q => q.tag_id).ToList(); allTagIdInList.AddRange(tagInList); } allTagIdInList = allTagIdInList.Distinct().ToList(); } if (allTagIdInList.Count > 0) { tagIdList = tagIdList.Intersect(allTagIdInList).ToArray(); } foreach (int i in tagIdList) { var tagModel = db.tags.FirstOrDefault(t => t.id == i); tTag tagItem = new tTag(); tagItem.id = i; tagItem.type = tagModel.type; tagItem.name = tagModel.name; tagList.Add(tagItem); } //typeList = db.places.Select(p => p.type).Distinct().ToArray(); //typeList = typeList.Distinct(); tagInfo = new { lists = placeList, system_tags = typeList, user_tags = tagList }; result = new { status = 1, data = tagInfo, msg = "" }; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage GetListDetail(viewModelGetListPlace getListInfo) { //無論公開或私人都會用此功能 所以要找創建清單的userid非登入者的userid List <string> systemTagResult = new List <string>(); List <int> resultplaceid = new List <int>(); List <int> searchallplaceinlist = new List <int>(); List <int> intersectResult = new List <int>(); List <int> tagsList = new List <int>(); List <int> editorIDList = new List <int>(); List <listDetailPlace> resultPlaceInfo = new List <listDetailPlace>(); List <tTag> resultTagInfo = new List <tTag>(); placeListInfo infoItem = new placeListInfo(); int[] tFilterid = getListInfo.filter; int list_createrId = 0; userFactory.userEventRecord(0, 1, db); var dataForm = new { info = infoItem, places = resultPlaceInfo, systemtags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; var result = new { status = 0, msg = "fail", data = dataForm }; var listModel = db.placeLists.Where(p => p.id == getListInfo.list_id).FirstOrDefault(); //此結果為特定清單中全部的地點id //無論公開或私人都會用此功能 所以要找創建清單的userid非登入者的userid if (listModel != null) { var editInList = db.placeListRelationships.Where(p => p.placelist_id == getListInfo.list_id).Select(q => q.user_id).ToList(); if (editInList != null) { foreach (int i in editInList) { editorIDList.Add(i); } dataForm = new { info = infoItem, places = resultPlaceInfo, systemtags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; } searchallplaceinlist = db.placeRelationships.Where(p => p.placelist_id == listModel.id).Select(q => q.place_id).ToList(); list_createrId = db.placeLists.Where(p => p.id == getListInfo.list_id).Select(q => q.user_id).FirstOrDefault(); var listCreator = db.users.Where(u => u.id == list_createrId).FirstOrDefault(); infoItem.id = listModel.id; infoItem.creator_id = listModel.user_id; infoItem.name = listModel.name; infoItem.creator_username = listCreator.name; infoItem.description = listModel.description; infoItem.privacy = listModel.privacy; infoItem.createdTime = listModel.created != null?listModel.created.ToString().Substring(0, 10) : ""; infoItem.updatedTime = listModel.updated != null?listModel.updated.ToString().Substring(0, 10) : ""; infoItem.coverImageURL = listModel.cover != null ? listModel.cover : null; dataForm = new { info = infoItem, places = resultPlaceInfo, systemtags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; result = new { status = 1, msg = "success", data = dataForm }; } //此結果為特定清單中篩選出有標籤的地點id if (tFilterid != null && list_createrId != 0) { intersectResult = searchallplaceinlist; foreach (int i in tFilterid) { //intersectResult = tagFactory.searchTag(list_createrId, ref intersectResult, i, db); intersectResult = tagFactory.searchTag(0, ref intersectResult, i, db); //var searchplacehastag = db.tagRelationships.Where(P => P.tag_id == i).Select(q => q.place_id).ToList(); //intersectResult = intersectResult.Intersect(searchplacehastag).ToList(); //foreach(int p in unionResult) { // resultplaceid.Add(p); //} //if (editorIDList.Count > 0) //{ // foreach (int editorId in editorIDList) // { // var placeInList = new List<int>(); // var editTagPlace = db.tagRelationships.Where(p => p.user_id == editorId && p.tag_id == i).Select(q => q.place_id).ToList(); // if (editTagPlace != null) // { // foreach (int placeId in editTagPlace) // { // placeInList.Add(db.placeRelationships.Where(p => p.place_id == placeId && p.placelist_id == getListInfo.list_id).Select(q => q.place_id).FirstOrDefault()); // } // if (placeInList.Count > 0) // { intersectResult.AddRange(placeInList); // //intersectResult= intersectResult.Intersect(placeInList).ToList(); // } // } // } //} } intersectResult = intersectResult.Distinct().ToList(); if (intersectResult.Count > 0) { foreach (int i in intersectResult) { var placeItem = db.places.Where(p => p.id == i).Select(q => q).FirstOrDefault(); if (placeItem != null) { if (placeItem.type != null) { systemTagResult.Add(placeItem.type); } listDetailPlace placeDetail = new listDetailPlace(); placeDetail.id = placeItem.id; placeDetail.gmap_id = placeItem.gmap_id; placeDetail.name = placeItem.name; placeDetail.phone = placeItem.phone; placeDetail.address = placeItem.address; placeDetail.type = placeItem.type; placeDetail.photo_url = placeItem.photo != null ? placeItem.photo : null; // photo type in db is byte[] resultPlaceInfo.Add(placeDetail); } tagsList.AddRange(db.tagRelationships.Where(p => p.place_id == i && p.user_id == list_createrId).Select(q => q.tag_id).ToList()); if (editorIDList.Count > 0) { foreach (int editorId in editorIDList) { tagsList.AddRange(db.tagRelationships.Where(p => p.place_id == i && p.user_id == editorId).Select(q => q.tag_id).ToList()); } }//var test = from p in db.tagRelations where p.place_id == i group p.tag_id by p.user_id == userlogin ?"userTag":"othersTag" into g select new {g.Key } ; } tagsList = tagsList.Distinct().ToList(); systemTagResult = systemTagResult.Distinct().ToList(); dataForm = new { info = infoItem, places = resultPlaceInfo, systemtags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; result = new { status = 1, msg = "success", data = dataForm }; } if (tagsList.Count > 0) { foreach (int i in tagsList) { var rtag = db.tags.Where(p => p.id == i && p.type == 2).Select(q => q).FirstOrDefault(); if (rtag != null) { tTag t = new tTag(); t.id = rtag.id; t.name = rtag.name; t.type = rtag.type; resultTagInfo.Add(t); } } } //var place = db.placeLists.Where(p => p.id == getListInfo.list_id).FirstOrDefault(); //var placeSpot = db.placeRelationships.Where(p => p.placelist_id == getListInfo.list_id).Select(p => p.place_id).ToList(); //List<placeListInfo> infoList = new List<placeListInfo>(); //List<tPlaceInfo> relationPlace = new List<tPlaceInfo>(); //List<tagInfo> tagInfoList = new List<tagInfo>(); //List<int> idList = new List<int>(); //List<int> tagList = new List<int>(); //for (int i = 0; i < placeSpot.Count(); i++) //{ // idList.Add(placeSpot[i]); //} //int[] terms = idList.ToArray(); //placeListInfo infoItem = new placeListInfo(); //infoItem.userId = place.user_id; //infoItem.name = place.name; //infoItem.description = place.description; //infoItem.privacy = place.privacy; //infoItem.createdTime = place.created.ToString(); //infoItem.updatedTime = place.updated.ToString(); ////byte[] binaryString = (byte[])place.cover; ////info.cover = Encoding.UTF8.GetString(binaryString); //infoList.Add(infoItem); //foreach (var i in terms) //{ // var tagId = db.tagRelationships.Where(p => p.place_id == i).Select(p => p.tag_id).ToList(); // tPlaceInfo exportPlaceInfo = new tPlaceInfo(); // var placeModel = db.places.FirstOrDefault(p => p.id == i); // for (int j = 0; j < tagId.Count(); j++) // { // tagList.Add(tagId[j]); // } // exportPlaceInfo.name = placeModel.name; // exportPlaceInfo.longitude = placeModel.longitude; // exportPlaceInfo.latitude = placeModel.latitude; // exportPlaceInfo.phone = placeModel.phone; // exportPlaceInfo.address = placeModel.address; // exportPlaceInfo.type = placeModel.type; // exportPlaceInfo.gmap_id = placeModel.gmap_id; // relationPlace.Add(exportPlaceInfo); //} //int[] tagArray = tagList.Distinct().ToArray(); //foreach (int t in tagArray) //{ // var exportTagInfo = new tagInfo(); // var tagInfoModel = db.tags.FirstOrDefault(p => p.id == t); // exportTagInfo.name = tagInfoModel.name; // exportTagInfo.type = tagInfoModel.type; // tagInfoList.Add(exportTagInfo); //} } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage GetListDetail(viewModelGetListPlace getListInfo) { //無論公開或私人都會用此功能 所以要找創建清單的userid非登入者的userid List <string> systemTagResult = new List <string>(); List <int> resultplaceid = new List <int>(); List <int> searchallplaceinlist = new List <int>(); List <int> intersectResult = new List <int>(); List <int> tagsList = new List <int>(); List <int> editorIDList = new List <int>(); List <int> kingTags = new List <int>(); List <listDetailPlace> resultPlaceInfo = new List <listDetailPlace>(); List <tTag> resultTagInfo = new List <tTag>(); placeListInfo infoItem = new placeListInfo(); int[] tFilterid = getListInfo.filter; int list_createrId = 0; int userlogin = 0; userlogin = userFactory.userIsLoginSession(userlogin); userlogin = userIsLoginCookie(userlogin); userFactory.userEventRecord(0, 1, db); var dataForm = new { info = infoItem, places = resultPlaceInfo, system_tags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; var result = new { status = 0, msg = "fail", data = dataForm }; var listModel = db.placeLists.Where(p => p.id == getListInfo.list_id).FirstOrDefault(); //此結果為特定清單中全部的地點id //無論公開或私人都會用此功能 所以要找創建清單的userid非登入者的userid if (listModel != null) { var editInList = db.placeListRelationships.Where(p => p.placelist_id == getListInfo.list_id).Select(q => q.user_id).ToList(); if (editInList != null) { foreach (int i in editInList) { editorIDList.Add(i); } dataForm = new { info = infoItem, places = resultPlaceInfo, system_tags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; } searchallplaceinlist = db.placeRelationships.Where(p => p.placelist_id == listModel.id).Select(q => q.place_id).ToList(); list_createrId = db.placeLists.Where(p => p.id == getListInfo.list_id).Select(q => q.user_id).FirstOrDefault(); var listCreator = db.users.Where(u => u.id == list_createrId).FirstOrDefault(); infoItem.id = listModel.id; infoItem.creator_id = listModel.user_id; infoItem.name = listModel.name; infoItem.creator_username = listCreator.name; infoItem.description = listModel.description; infoItem.privacy = listModel.privacy; infoItem.createdTime = listModel.created != null?listModel.created.ToString().Substring(0, 10) : ""; infoItem.updatedTime = listModel.updated != null?listModel.updated.ToString().Substring(0, 10) : ""; infoItem.coverImageURL = listModel.cover != null ? listModel.cover : null; dataForm = new { info = infoItem, places = resultPlaceInfo, system_tags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; result = new { status = 1, msg = "success", data = dataForm }; } //此結果為特定清單中篩選出有標籤的地點id if (tFilterid != null && list_createrId != 0) { intersectResult = searchallplaceinlist; foreach (int i in tFilterid) { intersectResult = tagFactory.searchTag(0, ref intersectResult, i, db); } intersectResult = intersectResult.Distinct().ToList(); if (intersectResult.Count > 0) { foreach (int i in intersectResult) { var placeItem = db.places.Where(p => p.id == i).Select(q => q).FirstOrDefault(); if (placeItem != null) { if (placeItem.type != null) { systemTagResult.Add(placeItem.type); } listDetailPlace placeDetail = new listDetailPlace(); if (userlogin == 0) { placeDetail.king_tags = kingTags.ToArray(); } else { var hasKingTag = db.tagRelationships.Where(t => t.user_id == userlogin && t.place_id == i && (t.tag_id == 101 || t.tag_id == 102 || t.tag_id == 103)).Select(t => t.tag_id).ToList(); if (hasKingTag != null) { placeDetail.king_tags = hasKingTag.ToArray(); } } location detailPlaceLocation = new location(); placeDetail.id = placeItem.id; placeDetail.gmap_id = placeItem.gmap_id; placeDetail.name = placeItem.name; placeDetail.phone = placeItem.phone; placeDetail.address = placeItem.address; placeDetail.type = placeItem.type; placeDetail.photo_url = placeItem.photo != null ? placeItem.photo : null; detailPlaceLocation.lon = placeItem.longitude; detailPlaceLocation.lat = placeItem.latitude; placeDetail.location = detailPlaceLocation; resultPlaceInfo.Add(placeDetail); } tagsList.AddRange(db.tagRelationships.Where(p => p.place_id == i && p.user_id == list_createrId).Select(q => q.tag_id).ToList()); if (editorIDList.Count > 0) { foreach (int editorId in editorIDList) { tagsList.AddRange(db.tagRelationships.Where(p => p.place_id == i && p.user_id == editorId).Select(q => q.tag_id).ToList()); } } } tagsList = tagsList.Distinct().ToList(); systemTagResult = systemTagResult.Distinct().ToList(); dataForm = new { info = infoItem, places = resultPlaceInfo, system_tags = systemTagResult, user_tags = resultTagInfo, editors_id = editorIDList }; result = new { status = 1, msg = "success", data = dataForm }; } if (tagsList.Count > 0) { foreach (int i in tagsList) { var rtag = db.tags.Where(p => p.id == i && p.type == 2).Select(q => q).FirstOrDefault(); if (rtag != null) { tTag t = new tTag(); t.id = rtag.id; t.name = rtag.name; t.type = rtag.type; resultTagInfo.Add(t); } } } } return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public HttpResponseMessage getMarkInfo(tGmap mapAOI) { var areaId = db.places.Where(p => (double)p.longitude > mapAOI.from.lon && (double)p.longitude <mapAOI.to.lon && (double)p.latitude> mapAOI.from.lat && (double)p.latitude < mapAOI.to.lat) .Select(p => p.id).ToList(); List <tMapMark> Marks = new List <tMapMark>(); List <string> systemTagResult = new List <string>(); List <tTag> resultTagInfo = new List <tTag>(); List <int> intersectResult = new List <int>(); List <int> tagsList = new List <int>(); int[] tFilterId = mapAOI.filter; int userlogin = 0; var mapInfo = new { marks = Marks, system_tags = systemTagResult, user_tags = resultTagInfo }; var result = new { status = 0, data = mapInfo, msg = "fail" }; //get intersect tagId by tags in filter intersectResult = areaId; if (tFilterId != null && tFilterId.Length > 0) { foreach (int i in tFilterId) { intersectResult = tagFactory.searchTag(userlogin, ref intersectResult, i, db); } intersectResult = intersectResult.Distinct().ToList(); } //get place information by intersectResult or all tags filter if (intersectResult != null) { foreach (int i in intersectResult) { var placeInfo = db.places.FirstOrDefault(t => t.id == i); tMapMark markItem = new tMapMark(); location location = new location(); markItem.place_id = placeInfo.id; location.lat = placeInfo.latitude; location.lon = placeInfo.longitude; markItem.location = location; tagsList.AddRange(db.tagRelationships.Where(p => p.place_id == i).Select(q => q.tag_id).ToList()); systemTagResult.Add(placeInfo.type); Marks.Add(markItem); } tagsList = tagsList.Distinct().ToList(); Array.Sort(tagsList.ToArray()); systemTagResult = systemTagResult.Distinct().ToList(); if (tagsList.Count > 0) { foreach (int i in tagsList) { var tagModel = db.tags.FirstOrDefault(p => p.id == i && p.type == 2); if (tagModel != null) { tTag tagItem = new tTag(); tagItem.id = tagModel.id; tagItem.name = tagModel.name; tagItem.type = tagModel.type; resultTagInfo.Add(tagItem); } } } mapInfo = new { marks = Marks, system_tags = systemTagResult, user_tags = resultTagInfo }; result = new { status = 1, data = mapInfo, msg = "" }; } return(Request.CreateResponse(HttpStatusCode.OK, result)); }