Ejemplo n.º 1
0
        public ActionResult <GetUserMusicResponse> GetUserMusic(GetUserMusicRequest request)
        {
            Guid?aimeId  = _aimeService.FindIdByCardId(request.UserId);
            var  profile = _context.FindProfileWithData(aimeId, p => p.Musics);

            UserMusic[] musics = Array.Empty <UserMusic>();

            if (profile != null)
            {
                musics = profile.Musics
                         .Distinct(UserMusicEqualityComparer.Instance)
                         .Skip(request.NextIndex)
                         .Take(request.MaxCount)
                         .Select(ObjectMapper.Map <UserMusic>)
                         .ToArray();
            }

            return(Ok(new GetUserMusicResponse
            {
                UserId = request.UserId,
                NextIndex = ChunithmUtility.NextPagination(musics, request),
                Length = musics.Length,
                UserMusicList = musics
            }));
        }
Ejemplo n.º 2
0
        public ActionResult <GetUserCourseResponse> GetUserCourse(GetUserCourseRequest request)
        {
            Guid?aimeId  = _aimeService.FindIdByCardId(request.UserId);
            var  profile = _context.FindProfileWithData(aimeId, p => p.Courses);

            UserCourse[] courses = Array.Empty <UserCourse>();

            if (profile != null)
            {
                courses = profile.Courses
                          .Skip(request.NextIndex)
                          .Take(request.MaxCount)
                          .Select(ObjectMapper.Map <UserCourse>)
                          .ToArray();
            }

            return(Ok(new GetUserCourseResponse
            {
                UserId = request.UserId,
                NextIndex = ChunithmUtility.NextPagination(courses, request),
                Length = courses.Length,
                UserCourseList = courses
            }));
        }
Ejemplo n.º 3
0
        public ActionResult <UpsertUserAllResponse> UpsertUserAll(UpsertUserAllRequest request)
        {
            if (request.UpsertUserAll == null)
            {
                // Invalid payload
                return(Ok());
            }

            var  payload = request.UpsertUserAll;
            Guid?aimeId  = _aimeService.FindIdByCardId(request.UserId);

            if (!aimeId.HasValue)
            {
                // AimeID not found
                return(Ok());
            }

            // Patch UserData.UserName (Double encoded UTF-8)
            var iso = Encoding.GetEncoding(28591);

            foreach (var userData in payload.UserData ?? Enumerable.Empty <UserProfile>())
            {
                userData.UserName = Encoding.UTF8.GetString(iso.GetBytes(userData.UserName));
            }

            // Upsert UserData(Profile)
            var profile = _context.FindProfile(aimeId);
            var isNew   = false;

            if (profile == null)
            {
                if (payload.UserData?.Length > 0)
                {
                    // New user
                    isNew          = true;
                    profile        = ObjectMapper.Map <DbUserProfile>(payload.UserData[0]);
                    profile.Id     = Guid.NewGuid();
                    profile.AimeId = aimeId !.Value;
                }
                else
                {
                    // ProfileId, UserData not found
                    return(new UpsertUserAllResponse());
                }
            }

            IEnumerable <DbUserGameOption> userGameOption = ChunithmUtility.PrepareDbObjects(
                ObjectMapper.Map <DbUserGameOption>(payload.UserGameOption),
                profile.Id);

            IEnumerable <DbUserGameOptionEx> userGameOptionEx = ChunithmUtility.PrepareDbObjects(
                ObjectMapper.Map <DbUserGameOptionEx>(payload.UserGameOptionEx),
                profile.Id);

            IEnumerable <DbUserDataEx> userDataEx = ChunithmUtility.PrepareDbObjects(
                ObjectMapper.Map <DbUserDataEx>(payload.UserDataEx),
                profile.Id);

            IEnumerable <DbUserMap> userMapList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserMap>(payload.UserMapList),
                profile);

            IEnumerable <DbUserCharacter> userCharacterList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserCharacter>(payload.UserCharacterList),
                profile);

            IEnumerable <DbUserItem> userItemList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserItem>(payload.UserItemList),
                profile);

            IEnumerable <DbUserMusic> userMusicDetailList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserMusic>(payload.UserMusicDetailList),
                profile);

            IEnumerable <DbUserActivity> userActivityList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserActivity>(payload.UserActivityList),
                profile);

            IEnumerable <DbUserPlayLog> userPlayLogList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserPlayLog>(payload.UserPlayLogList),
                profile);

            IEnumerable <DbUserCourse> userCourseList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserCourse>(payload.UserCourseList),
                profile);

            IEnumerable <DbUserDuelList> userDuelList = PrepareProfileObjects(
                ObjectMapper.Map <DbUserDuelList>(payload.UserDuelList),
                profile);

            using var transaction = _context.Database.BeginTransaction();

            try
            {
                if (payload.UserData?.Length > 0)
                {
                    // profile: tracking entity
                    ObjectMapper.Map(payload.UserData[0], profile);
                }

                if (isNew)
                {
                    _context.Profiles.Add(profile);
                    _context.SaveChanges();
                }

                _context.UpsertRange(userDataEx).On(o => o.Id).Run();
                _context.UpsertRange(userGameOption).On(o => o.Id).Run();
                _context.UpsertRange(userGameOptionEx).On(o => o.Id).Run();
                _context.UpsertRange(userActivityList).On(o => new { o.ProfileId, o.Kind, o.ActivityId }).Run();
                _context.UpsertRange(userCharacterList).On(o => new { o.ProfileId, o.CharacterId }).Run();
                _context.UpsertRange(userCourseList).On(o => new { o.ProfileId, o.CourseId }).Run();
                _context.UpsertRange(userDuelList).On(o => new { o.ProfileId, o.DuelId }).Run();
                _context.UpsertRange(userItemList).On(o => new { o.ProfileId, o.ItemKind, o.ItemId }).Run();
                _context.UpsertRange(userMapList).On(o => new { o.ProfileId, o.MapId }).Run();
                _context.UpsertRange(userMusicDetailList).On(o => new { o.ProfileId, o.MusicId, o.Level }).Run();
                _context.AddRange(userPlayLogList);
                _context.SaveChanges();

                transaction.Commit();

                return(Ok(new UpsertUserAllResponse
                {
                    ReturnCode = 1
                }));
            }
            catch (Exception e)
            {
                Log.Fatal(e, e.Message);

                transaction.Rollback();
                return(new UpsertUserAllResponse());
            }
        }