public HttpResponseMessage SignOutActivity([FromBody] IdModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/signoutactivity") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User volunteer = ValidationService.FindUserWithToken(GetToken()); Activity activity = (Activity)myService.FindOneById(new Guid(model.id)); if (activity == null || volunteer == null) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("请求不合法", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } /* * myService.VolunteerSignOutActivity(volunteer, activity); * return new HttpResponseMessage(HttpStatusCode.OK); */ if (activity.SignOut(volunteer)) { return(new HttpResponseMessage(HttpStatusCode.Accepted)); } else { return new HttpResponseMessage { StatusCode = HttpStatusCode.NotAcceptable, Content = new StringContent("volunteer与activity状态错误,无法sign out", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") } }; }
public HttpResponseMessage GetUserBadges(string id, string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/badge/userbadges?id=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid userId = new Guid(id); User user = myService.FindUser(userId); User currentUser = ValidationService.FindUserWithToken(GetToken()); //如果当前用户和user都是volunteer,必须是自己或者好友才能调用该web api看到badge if (user.UserRole.Contains(Role.Volunteer) && currentUser.UserRole.Contains(Role.Volunteer)) { if (currentUser.Id != userId) { if (FriendService.CheckIfWeAreFriends(currentUser.Id, userId) == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } } } List <BadgeEntity> source = BadgeService.FindAllUserGrantedBadgeEntity(userId, sortByKey, isAscending, pageIndex, pageSize); var result = transformBadgeEntityToListShow(source); StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); return(new HttpResponseMessage { Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage Members(string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organization/members?sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organization = ValidationService.FindUserWithToken(GetToken()); List <object> Curs = new List <object>(); foreach (var organizer in myService.FindAllOrganizerByOrganization(organization, sortByKey, isAscending, pageIndex, pageSize)) { var Cur = new { organizerName = organizer.Name, organizerId = organizer.Id, email = organizer.Email, time = ((OrganizerProfile)organizer.UserProfiles[organizer.Name + "OrganizerProfile"]).MyOrganizations[organization.Id], avatar = ((OrganizerProfile)organizer.UserProfiles[organizer.Name + "OrganizerProfile"]).Avatar }; Curs.Add(Cur); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, Curs, Curs.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage AcceptFriend([FromBody] IdAndCommentModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/acceptfriend") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid otherVolunteerId = new Guid(model.id); User myself = ValidationService.FindUserWithToken(GetToken()); User other = myService.FindUser(otherVolunteerId); Guid myId = myself.Id; //检查是否已经是好友 if (FriendService.CheckIfWeAreFriends(myId, otherVolunteerId) == true) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("你们已经是好友了", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } //同意好友申请并添加好友 if (myService.FriendServiceInVolunteerService.AcceptFriendApplication(other, myself, model.comment) == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("同意好友申请不成功", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } else { return(new HttpResponseMessage(HttpStatusCode.OK)); } }
public HttpResponseMessage SearchNotMyFriendByFilter(string email, string friendName, string affiliation) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/searchnotmyfriendbyfilter?email=&friendname=&affiliation=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User me = ValidationService.FindUserWithToken(GetToken()); var source = myService.FriendServiceInVolunteerService.SearchNotMyFriendByFilter(me.Id, email, friendName, affiliation); List <object> result = new List <object>(); foreach (User volunteer in source) { var a = new { id = volunteer.Id, name = volunteer.Name, avatar = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).Avatar, description = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).Description, level = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).VolunteerLevel }; result.Add(a); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage GetActivityToCheckOut(string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organizer/activitytocheckout?sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User CurrentUser = ValidationService.FindUserWithToken(GetToken()); List <Activity> result = new List <Activity>(); foreach (Activity activity in myService.FindActivatedActivitesByOrganizerId(CurrentUser.Id, "", sortByKey, isAscending, pageIndex, pageSize)) { if (activity.Status == ActivityStatus.RunningCheckIn || activity.Status == ActivityStatus.Finished || activity.Status == ActivityStatus.RunningSignInAndCheckIn) { result.Add(activity); } } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage BreakOffFriendship([FromBody] IdModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/breakofffriendship") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid otherVolunteerId = new Guid(model.id); User myself = ValidationService.FindUserWithToken(GetToken()); User other = myService.FindUser(otherVolunteerId); Guid myId = myself.Id; if (FriendService.CheckIfWeAreFriends(myId, otherVolunteerId) == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("你们不是好友,无法断绝关系", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } if (myService.FriendServiceInVolunteerService.BreakOffFriendship(myself, other) == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("断绝好友关系不成功", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } else { return(new HttpResponseMessage(HttpStatusCode.OK)); } }
public HttpResponseMessage GetUserBadgeDetail(string id, string badgeName) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/badge/userbadgedetail?id=&badgename=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } List <BadgeEntity> badgeEntities = BadgeService.FindAllUserGrantedBadgeEntity(new Guid(id)); foreach (BadgeEntity badgeEntity in badgeEntities) { if (badgeEntity.BadgeName == badgeName) { BadgeDescription badgeDescription = BadgeService.FindBadgeDescriptionByName(badgeEntity.BadgeName); var result = new { badgeName = badgeEntity.BadgeName, badgeDescription = badgeDescription.Description, badgePicture = badgeDescription.Picture, badgeGrantedTime = badgeEntity.GrantedTime, badgeRequirementDescription = badgeDescription.RequirementDescription.Values }; StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); return(new HttpResponseMessage { Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); } } return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("未找到该badge", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage GetOrganizationStatistics(string id) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organization/statistics?id=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organization = myService.FindUser(new Guid(id)); var result = new { TotalPointEachMonth = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).TotalPointEachMonth, RemainingSum = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).RemainingSum, ConsumeAllPoint = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).ConsumeAllPoint, AllActivityCount = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).AllActivityCount, AllVolunteerCount = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).AllVolunteerCount, StatisticsPerMonth = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).OrganizationStatistics }; StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage GetAll(string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organization?sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } List <object> Curs = new List <object>(); foreach (var o in myService.FindAllOrganizations(sortByKey, isAscending, pageIndex, pageSize)) { var Cur = new { name = o.Name, id = o.Id }; Curs.Add(Cur); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, Curs, Curs.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage GetMyFriends(string id) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/myfriends?id=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid myId = new Guid(id); List <object> result = new List <object>(); IEnumerable <User> myFriendsOrderByPoint = myService.FriendServiceInVolunteerService.MyFriends(myId, "", false, 0, 0); foreach (User volunteer in myFriendsOrderByPoint) { var a = new { id = volunteer.Id, name = volunteer.Name, avatar = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).Avatar, description = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).Description, level = ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).VolunteerLevel, }; result.Add(a); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage MyViewedActivities(ActivityStage stage, string filterSource, string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/viewedactivities?stage=&filterSource=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User currentUser = ValidationService.FindUserWithToken(GetToken()); if (!currentUser.UserRole.Contains(Role.Volunteer)) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } List <Activity> activities = myService.FindAllActivitiesWhichVolunteerViewed(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize).ToList <Activity>(); List <ActivityToListShow> result = transformActivityToListShow(activities, currentUser); StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); return(new HttpResponseMessage { Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage ActivitySendSMSQRCode([FromBody] GenerateSendSMSQRCodeModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/organizer/activitysendsmsqrcode") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } //到期时间为当前时间之后 3 小时 DateTime expireTime = DateTime.Now + new TimeSpan(3, 0, 0); ActionValidationModel actionValidate = myService.ActionValidationService.GenerateActionValidate("ActivitySendSMS", model, expireTime); MemoryStream ms = new MemoryStream(); myService.ActionValidationService.GenerateQRCode("activitysendsms," + actionValidate.Id.ToString(), ms); byte[] buffer = ms.GetBuffer(); string base64 = Convert.ToBase64String(buffer); var result = new { expireTime = expireTime, image = base64 }; StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); return(new HttpResponseMessage { StatusCode = HttpStatusCode.Accepted, Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage GetMyFriendsRank(string id, string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/myfriendsrank?id=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid myId = new Guid(id); List <VolunteerAndFriendsRankModel> result = new List <VolunteerAndFriendsRankModel>(); if (sortByKey == "" || sortByKey == "point" || sortByKey == "activityCount" || sortByKey == "badgeCount") { result = myService.FriendServiceInVolunteerService.MeAndMyFriendsRank(myId, sortByKey, isAscending, pageIndex, pageSize); } else { return(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("sortByKey参数错误", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage QuitOrganization([FromBody] IdModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/organizer/quit") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organizer = ValidationService.FindUserWithToken(GetToken()); User organization = myService.FindUser(new Guid(model.id)); if (organization == null) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Organization不存在", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } if (myService.OrganizerQuitOrganization(organizer, organization)) { //myService.MessageService.SendMessage("System", organizer.Id, "你主动离开了组织", "你主动离开了组织" + organization.Name, null, null, false); //myService.MessageService.SendMessage("System", organization.Id, "有人离开了组织", organizer.Name + "离开了组织", null, null, false); return(new HttpResponseMessage(HttpStatusCode.OK)); } return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("请求不合法", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage RecommendFriend(string id, int number) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/recommendfriend?id=&number=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User volunteer = myService.FindUser(new Guid(id)); var source = myService.FriendServiceInVolunteerService.RecommendFriends(volunteer, number); List <object> result = new List <object>(); foreach (User recommend in source) { var a = new { id = recommend.Id, name = recommend.Name, avatar = ((VolunteerProfile)recommend.UserProfiles[recommend.Name + "VolunteerProfile"]).Avatar, description = ((VolunteerProfile)recommend.UserProfiles[recommend.Name + "VolunteerProfile"]).Description }; result.Add(a); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string json = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage JoinOrganization([FromBody] IdAndCommentModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/organizer/join") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User CurrentUser = ValidationService.FindUserWithToken(GetToken()); User Organization = myService.FindUser(new Guid(model.id)); if (Organization == null) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Organization不存在", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } if (myService.OrganizerApplyToJoinOrganization(CurrentUser, Organization, model.comment)) { return(new HttpResponseMessage(HttpStatusCode.OK)); } return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("请求不合法", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage AppliedOrganization(string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organizer/appliedorganization?sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organizer = ValidationService.FindUserWithToken(GetToken()); List <object> Curs = new List <object>(); string json = ""; if (organizer.UserRole.Contains(Role.Organizer)) { foreach (var organization in myService.FindAllAppliedOrganizationByOrganizer(organizer, sortByKey, isAscending, pageIndex, pageSize)) { var Cur = new { name = organization.Name, id = organization.Id, avatar = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).Avatar, description = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).Description }; Curs.Add(Cur); } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, Curs, Curs.GetType()); json = tw.ToString(); } return(new HttpResponseMessage { Content = new StringContent(json, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage UploadActivityImage() { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/content/uploadactivityimage") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count != 1) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("error", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } var postedFile = httpRequest.Files[0]; string imageName = Guid.NewGuid().ToString(); //生成图像名称 string path = "/Static/Images/Activity/" + imageName + postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(".")); //相对路径+图像名称+图像格式 string filePath = HttpContext.Current.Server.MapPath("~" + path); //绝对路径 Stream fileStream = postedFile.InputStream; HandleImageService.CutForCustom(fileStream, filePath, 960, 720, 75);//剪裁为960*720并保存图像到本地 fileStream.Close(); return(new HttpResponseMessage { StatusCode = HttpStatusCode.Created, Content = new StringContent(path, System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage SignInActivity([FromBody] IdModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/signinactivity") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User volunteer = ValidationService.FindUserWithToken(GetToken()); Activity activity = (Activity)myService.FindOneById(new Guid(model.id)); if (activity == null || volunteer == null) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("请求不合法", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } //判断volunteer badge是否满足条件 if (myService.ActivityValidateBadgeLimit(activity, volunteer.Id) == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.NotAcceptable, Content = new StringContent("volunteer的badge不符合要求,无法sign in", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } if (activity.SignIn(volunteer)) { return(new HttpResponseMessage(HttpStatusCode.Accepted)); } else { return new HttpResponseMessage { StatusCode = HttpStatusCode.NotAcceptable, Content = new StringContent("volunteer与activity状态错误,无法sign in", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") } }; }
public HttpResponseMessage GetAndroidapp(int version) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/mobileapp/androidapp?version=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } string androidFolderPath = HttpRuntime.AppDomainAppPath + "Static\\Mobile\\Android"; DirectoryInfo dir = new DirectoryInfo(androidFolderPath); int latestVersion = 1; List <int> versions = new List <int>(); //android app各个版本的文件夹 foreach (DirectoryInfo folder in dir.GetDirectories()) { try { versions.Add(Convert.ToInt32(folder.Name)); } catch { continue; } } //找到最新版本号 foreach (int v in versions) { if (latestVersion < v) { latestVersion = v; } } DownloadAndroidappModel result = new DownloadAndroidappModel(); if (latestVersion > version) { //不是最新版本 result.isLatest = false; result.changelog = File.ReadAllText(androidFolderPath + "\\Latest\\changelog.txt"); result.downloadAppLink = "/Static/Mobile/Android/Latest/app-release.apk"; } else { //已经是最新版本 result.isLatest = true; } StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); string jsonString = tw.ToString(); return(new HttpResponseMessage { Content = new StringContent(jsonString, System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage Members() { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organization/members") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } return(Members("Name", true, 0, 0)); }
public HttpResponseMessage ApplyFromMeHistory() { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/applyfrommehistory") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } return(ApplyFromMeHistory("ActionTime", false, 0, 0)); }
public HttpResponseMessage MyFavoriteActivities(ActivityStage stage, string filterSource, string sortByKey, bool isAscending, int pageIndex, int pageSize) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/favorite?stage=&filterSource=&sortByKey=&isAscending=&pageIndex=&pageSize=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User currentUser = ValidationService.FindUserWithToken(GetToken()); if (!currentUser.UserRole.Contains(Role.Volunteer)) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } IEnumerable <Activity> source; switch (stage) { //找到所有非draft状态的activity case ActivityStage.all: source = myService.FindAllActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize); break; //即将开始的activity(处于active、maxVolunteer、ready、signIn状态下的) case ActivityStage.aboutToStart: source = myService.FindAboutToStartActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize); break; //正在进行的活动(处于RunningCheckIn、RunningRun状态下的) case ActivityStage.running: source = myService.FindRunningActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize); break; //已经完成的活动(处于Finished状态下的) case ActivityStage.finish: source = myService.FindFinishedActivitiesWhichVolunteerFavorite(currentUser, filterSource, sortByKey, isAscending, pageIndex, pageSize); break; default: return(new HttpResponseMessage { StatusCode = HttpStatusCode.Forbidden, Content = new StringContent("stage参数错误", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } List <ActivityToListShow> result = transformActivityToListShow(source, currentUser); StringWriter tw = new StringWriter(); JsonSerializer jsonSerializer = new JsonSerializer(); jsonSerializer.Serialize(tw, result, result.GetType()); return(new HttpResponseMessage { Content = new StringContent(tw.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/json") }); }
public HttpResponseMessage ClearViewActivityHistory() { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/volunteer/clearviewedactivityhistory") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User currentUser = ValidationService.FindUserWithToken(GetToken()); myService.ClearVolunteerViewActivityRecord(currentUser); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public HttpResponseMessage GetAllBadgeCount() { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/badge/allbadgecount") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } var result = BadgeService.FindAllBadgeCount(); return(new HttpResponseMessage { Content = new StringContent(result.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage SetOrganizationRemainingPoint([FromBody] SetPointModel model) { if (ValidationService.AuthorizeToken(GetToken(), "post:/api/organization/setremainingpoint") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organization = myService.FindUser(new Guid(model.id)); ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).RemainingSum = model.point; organization.Save(); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public HttpResponseMessage GetOrganizationRemainingPoint(string id) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/organization/remainingpoint?id=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User organization = myService.FindUser(new Guid(id)); double remainingSum = ((OrganizationProfile)organization.UserProfiles[organization.Name + "OrganizationProfile"]).RemainingSum; return(new HttpResponseMessage { Content = new StringContent(remainingSum.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }
public HttpResponseMessage EditAffiliation([FromBody] AffiliationModel model) { if (ValidationService.AuthorizeToken(GetToken(), "put:/api/volunteer/affiliation") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } User volunteer = ValidationService.FindUserWithToken(GetToken()); ((VolunteerProfile)volunteer.UserProfiles[volunteer.Name + "VolunteerProfile"]).Affiliation = ParseToList(model.affiliations); myService.AffiliationService.AddTag(model.affiliations); volunteer.Save(); return(new HttpResponseMessage(HttpStatusCode.OK)); }
public HttpResponseMessage GetMyFriendCount(string id) { if (ValidationService.AuthorizeToken(GetToken(), "get:/api/volunteer/myfriendcount?id=") == false) { return(new HttpResponseMessage { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("无访问权限", System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); } Guid myId = new Guid(id); int result = FriendService.FindMyFriends(myId).Count; return(new HttpResponseMessage { Content = new StringContent(result.ToString(), System.Text.Encoding.GetEncoding("UTF-8"), "application/text") }); }