Esempio n. 1
0
        public async Task <MessageReport> DeviceRegister(OS_DeviceRegisterModel model)
        {
            var result = new MessageReport(false, "có lỗi xảy ra");

            try
            {
                //Kiểm tra tồn tại
                var existed = await _OS_PlayerService.GetByPlayerId_UserId(model.DeviceId, model.UserId);

                if (existed == null)
                {
                    existed = new Kztek_Model.Models.OneSignalr.OS_Player()
                    {
                        Id       = ObjectId.GenerateNewId().ToString(),
                        UserId   = model.UserId,
                        PlayerId = model.DeviceId
                    };

                    result = await _OS_PlayerService.Create(existed);
                }

                result = new MessageReport(true, "Đã đăng ký");
            }
            catch (System.Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(result);
        }
Esempio n. 2
0
        public async Task <IActionResult> OneSignalrRegister(OneSignalrSubmit model)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            try
            {
                //Lấy người dùng hiện tại
                var user = await SessionCookieHelper.CurrentUser(this.HttpContext);

                if (user == null)
                {
                    result = new MessageReport(false, "Chưa đăng nhập");
                    return(Json(result));
                }

                if (string.IsNullOrWhiteSpace(model.PlayerId))
                {
                    result = new MessageReport(false, "Chưa có Player id");
                    return(Json(result));
                }

                //
                var existed = await _OS_PlayerService.GetByPlayerId_UserId(model.PlayerId, user.UserId);

                if (existed == null)
                {
                    existed = new Kztek_Model.Models.OneSignalr.OS_Player()
                    {
                        Id       = ObjectId.GenerateNewId().ToString(),
                        UserId   = user.UserId,
                        PlayerId = model.PlayerId
                    };

                    result = await _OS_PlayerService.Create(existed);
                }
                else
                {
                    result = new MessageReport(true, "Đã đăng ký");
                }
            }
            catch (Exception ex)
            {
                result = new MessageReport(false, ex.Message);
            }

            return(Json(result));
        }