public override async Task OnConnectedAsync()
        {
            var Token = _httpContextAccessor.HttpContext.Request.Query["type"].ToString();


            if (Token == "ClientToken")
            {
                var clientGroup = await _clientGroupService.CreateClientGroup(Context.ConnectionId);

                await Groups.AddToGroupAsync(Context.ConnectionId, clientGroup.ToString());

                await Clients.Caller.SendAsync("ReceiveMessage", "Hi Mr", DateTimeOffset.UtcNow, "Welcome Client");

                await base.OnConnectedAsync();
            }

            if (Token == "ShopToken")
            {
                Random r = new Random();

                var shopId    = r.Next(500);
                var shopGroup = await _shopGroupService.CreateShopGroup(Context.ConnectionId, shopId.ToString());

                await Groups.AddToGroupAsync(Context.ConnectionId, shopGroup.ToString());

                await Clients.Caller.SendAsync("ReceiveMessage", "Your Id is = " + shopId + "", DateTimeOffset.UtcNow, "Welcome Shop");

                await base.OnConnectedAsync();
            }


            await base.OnConnectedAsync();

            return;
        }
示例#2
0
        public ActionResult CreateGroup(ClientGroupFormModel formModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newGroup = Mapper.Map <ClientGroupFormModel, ClientGroup>(formModel);

                    clientGroupService.CreateClientGroup(newGroup);
                    clientGroupService.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }