Пример #1
0
        public override async Task <GameService.GetGameEventsReply> GetGameEvents(GetGameEventsRequest request, ServerCallContext context)
        {
            try
            {
                var session = await context.GetSession();

                if (session == null)
                {
                    return(new GetGameEventsReply()
                    {
                        Code = ErrorCode.LostSession
                    });
                }

                var events = await GameEventQuery.Gets(session.member_no, session.user_no);

                // 이벤트 초기화
                if (events.Count == 0)
                {
                    var nextDate = DateTime.UtcNow.AddDays(1).Date;
                    var endTime  = new DateTime(nextDate.Year, nextDate.Month, nextDate.Day, 0, 0, 0, DateTimeKind.Utc);

                    var game_event = new Models.GameEvent()
                    {
                        user_no  = session.user_no,
                        event_id = 1,
                        reward   = 0,
                        occ_time = endTime,
                    };
                    events.Add(game_event);
                    await GameEventQuery.Add(session.member_no, game_event);
                }

                // 이벤트 목록 생성
                var reply = new GetGameEventsReply();
                reply.Code = ErrorCode.Success;
                foreach (var game_event in events)
                {
                    reply.Events.Add(new EventInfo()
                    {
                        EventId         = game_event.event_id,
                        IsReward        = (game_event.reward == 0 ? false : true),
                        RewardStartTime = DateTime.SpecifyKind(game_event.occ_time, DateTimeKind.Utc).ToTimestamp(),
                        RewardItemId    = (int)GameItemId.OpenEventBox,
                    });
                }

                return(reply);
            }
            catch (Exception ex)
            {
                Log.Error($"GetGameEvents {ex.ToString()}");

                return(new GetGameEventsReply()
                {
                    Code = ErrorCode.WrongParam
                });
            }
        }
        public static async Task <Models.GameEvent> Add(long member_no, Models.GameEvent entity)
        {
            using (var context = new Lobby.Models.GameContext(member_no))
            {
                context.game_event.Add(entity);
                await context.SaveChangesAsync();

                return(entity);
            }
        }
        public static async Task <bool> Update(long member_no, Models.GameEvent entity)
        {
            try
            {
                using (var context = new Lobby.Models.GameContext(member_no))
                {
                    var row = await context.game_event.Where(x => x.event_no == entity.event_no).FirstOrDefaultAsync();

                    if (row != null && row != default(Models.GameEvent))
                    {
                        row.Copy(entity);
                        await context.SaveChangesAsync();

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error($"{e.ToString()}");
                return(false);
            }
            return(true);
        }
Пример #4
0
 public void Copy(GameEvent other)
 {
     event_id = other.event_id;
     reward   = other.reward;
     occ_time = other.occ_time;
 }