public IActionResult GetByIDs([FromQuery(Name = "ids")] string idsString) { var api = Api.INSTANCE; try { uint[] ids = Array.ConvertAll(idsString.Split(","), uint.Parse); using (var da = api.DAFactory.Get()) { var avatars = da.Avatars.GetMultiple(ids); List <JSONAvatar> avatarJson = new List <JSONAvatar>(); foreach (var avatar in avatars) { avatarJson.Add(new JSONAvatar { avatar_id = avatar.avatar_id, shard_id = avatar.shard_id, name = avatar.name, gender = avatar.gender, date = avatar.date, description = avatar.description, current_job = avatar.current_job, mayor_nhood = avatar.mayor_nhood }); } var avatarsJson = new JSONAvatars(); avatarsJson.avatars = avatarJson; return(ApiResponse.Json(HttpStatusCode.OK, avatarsJson)); } } catch { return(ApiResponse.Json(HttpStatusCode.NotFound, new JSONAvatarError("Error during cast. (invalid_value)"))); } }
public IActionResult GetByUser() { var api = Api.INSTANCE; var user = api.RequireAuthentication(Request); if (!user.Claims.Contains("userReadPermissions")) { return(ApiResponse.Json(HttpStatusCode.OK, new JSONAvatarError("No read premissions found."))); } using (var da = api.DAFactory.Get()) { var avatars = da.Avatars.GetByUserId(user.UserID); List <JSONAvatar> avatarJson = new List <JSONAvatar>(); foreach (var avatar in avatars) { avatarJson.Add(new JSONAvatar { avatar_id = avatar.avatar_id, shard_id = avatar.shard_id, name = avatar.name, gender = avatar.gender, date = avatar.date, description = avatar.description, current_job = avatar.current_job, mayor_nhood = avatar.mayor_nhood }); } var avatarsJson = new JSONAvatars(); avatarsJson.avatars = avatarJson; return(ApiResponse.Json(HttpStatusCode.OK, avatarsJson)); } }
public IActionResult GetByNhood(int shardId, uint nhoodId) { var api = Api.INSTANCE; using (var da = api.DAFactory.Get()) { var lots = da.Lots.All(shardId).Where(x => x.neighborhood_id == nhoodId); if (lots == null) { return(ApiResponse.Json(HttpStatusCode.NotFound, new JSONAvatarError("Lots not found"))); } List <JSONAvatar> avatarJson = new List <JSONAvatar>(); foreach (var lot in lots) { if (lot.category != FSO.Common.Enum.LotCategory.community) { var roomies = da.Roommates.GetLotRoommates(lot.lot_id).Where(x => x.is_pending == 0).Select(x => x.avatar_id); var avatars = da.Avatars.GetMultiple(roomies.ToArray()); foreach (var avatar in avatars) { avatarJson.Add(new JSONAvatar { avatar_id = avatar.avatar_id, shard_id = avatar.shard_id, name = avatar.name, gender = avatar.gender, date = avatar.date, description = avatar.description, current_job = avatar.current_job, mayor_nhood = avatar.mayor_nhood }); } } } var avatarsJson = new JSONAvatars(); avatarsJson.avatars = avatarJson; return(ApiResponse.Json(HttpStatusCode.OK, avatarsJson)); } }