Exemple #1
0
        public AdminStoreItem(ProductStoreDataModel dbModel, AdminStoreData parendData)
        {
            Id         = dbModel.Id;
            DateCreate = dbModel.Date.ToString("s");
            NativeName = dbModel.Property.TranslateText.En.Name;
            Active     = !dbModel.Trash;
            Properties = dbModel.Property.Property;

            ProductTypeIds tType;

            Enum.TryParse(dbModel.ProductTypeId.ToString(), out tType);

            ProductType = new NameIdInt((int)tType, tType.ToString());

            ImagePath = dbModel.Property.ImgCollectionImg.Store;
            L10N      = dbModel.Property.TranslateText;
            Currency  = parendData.CurrencyList[tType == ProductTypeIds.Cc ? 0 : 1];
            Price     = (double)dbModel.Cost;

            Duration = parendData.DurationList[0];
            if (tType == ProductTypeIds.Premium)
            {
                var premProps = ProductPropertyHelper.GetPremiumProperties(Properties);
                Duration = _getDaysFromSecond(premProps.Duration, parendData.DurationList);
            }
            else if (tType == ProductTypeIds.Booster)
            {
                var props = ProductPropertyHelper.GetBooserProperty(Properties);
                Duration = _getDaysFromSecond(props.Duration, parendData.DurationList);
            }
        }
        public async Task <GroupChannelOut> UserChannelsJoinToGroupChannel(int channelId, string password)
        {
            NameIdInt channelOwner = null;

            try
            {
                return(await _contextActionAsync(async connection =>
                {
                    var cr = _getCurrentUser(connection);
                    ChannelConnectionUserOut newConnectionUser = null;
                    var chOut = _channelService.JoinUserToGroupChannel(connection, channelId, password, cr.UserId,
                                                                       (owner, conOut) =>
                    {
                        channelOwner = owner;
                        newConnectionUser = conOut;
                    });
                    await cr.AddOrReplaceGroupChannelGroupNameAsync(Groups, channelId, chOut.ChannelName);
                    var updHubUser = _hubCache.AddOrUpdateLocal(cr, true);
                    await Clients.Client(updHubUser.ConnectionId).InvokeAsync("updateConnectionUser", updHubUser);
                    if (channelOwner == null || newConnectionUser == null)
                    {
                        throw new NotImplementedException(
                            "data correct but target admin or new connection user not exist");
                    }
                    var admin = _getOnlineSingleUser(connection, channelOwner.Id);
                    if (admin != null)
                    {
                        newConnectionUser.UserName = cr.Name;
                        await Clients.Client(admin.ConnectionId).InvokeAsync("onUserChannelsGroupUserSubscribe",
                                                                             admin.UserId, newConnectionUser);
                    }
                    return chOut;
                }));
            }
            catch (Exception e)
            {
                e.Data.Add("ChannelOwner", channelOwner);
                throw new HubException(e.Message, e);
            }
        }
Exemple #3
0
 public IActionResult PostTest(NameIdInt model)
 {
     return(Json(model));
 }
        public GroupChannelOut JoinUserToGroupChannel(IDbConnection connection, int channelId, string password, int userId, Action <NameIdInt, ChannelConnectionUserOut> setChannelOwnerAndUserOut)
        {
            GroupChannelOut result    = null;
            var             groupType = (byte)ChannelTypes.Group;

            var channel = _channelRepo.GetChannelWithConnectedUsers(connection, channelId, new List <int>());

            if (channel == null)
            {
                throw new Exception(Error.ChannelNotExist);
            }
            if (channel.creatorId == userId)
            {
                throw new NotImplementedException("is creator user channel must be exist before");
            }

            var admin = new NameIdInt(channel.creatorId, channel.creatorName);

            if (channel.password != password)
            {
                setChannelOwnerAndUserOut(admin, null);
                throw new SecurityException(Error.NotPermitted);
            }
            var maxLimit          = (int)MaxLenghtConsts.GroupChannelsLimit;
            var channelConnection = channel.GetConnections().SingleOrDefault(i => i.userId == userId && i.channelType == groupType);

            ChannelConnectionDataModel targetChannelConnectionData;

            if (channelConnection == null)
            {
                var chConnCount = _channelConnRepo.GetCountConectionsForUser(connection, userId);
                var canAdd      = chConnCount <= maxLimit - 1;
                if (!canAdd)
                {
                    throw new Exception(Error.MaxChannelsLimit);
                }
                targetChannelConnectionData = new ChannelConnectionDataModel
                {
                    UserId      = userId,
                    Password    = password,
                    MessageRead = true,
                    MessageSend = true,
                    ChannelType = ChannelTypes.Group,
                    ChannelId   = channel.Id
                };
                var entyty = _channelConnRepo.ConvertToEntity(targetChannelConnectionData);
                entyty = _channelConnRepo.AddOrUpdate(connection, entyty);
                targetChannelConnectionData.Id = entyty.Id;
            }
            else
            {
                if (!channelConnection.messageRead)
                {
                    setChannelOwnerAndUserOut(admin, null);
                    throw new SecurityException(Error.YouAreBlockedInThisChannel);
                }
                // ReSharper disable once InvertIf
                if (channelConnection.password != password)
                {
                    channelConnection.password = password;
                    var updated = _channelConnRepo.Update(connection, channelConnection);
                    if (!updated)
                    {
                        throw new NotImplementedException();
                    }
                }

                targetChannelConnectionData = _channelConnRepo.ConvertToWorkModel(channelConnection);
            }

            var channelData = channel.ConvertToWorkModel();

            setChannelOwnerAndUserOut(admin, new ChannelConnectionUserOut(targetChannelConnectionData, "", password));
            var channelOut = new GroupChannelOut(channelData, userId);

            channelOut.SetMessages(connection, _channelMessageRepo);
            channelOut.SetBtnSend(targetChannelConnectionData.MessageSend);
            channelOut.SetComplexButtonView();
            result = channelOut;
            return(result);
        }