public async Task <SimpleTradeInfo> InitiateTrade(string inputCoinType, decimal?amount)
        {
            _logger.LogInformation($"[InitiateTrade] Starting InitiateTrade with inputCoinType: {inputCoinType} and amount: {amount}");

            var now      = DateTime.UtcNow;
            var memoGuid = Guid.NewGuid().ToString();

            var r1 = await _blockTradeService.InitiateTrade(inputCoinType, _mappingTradingExchange[inputCoinType], "tst-ll-reception", memoGuid);

            _logger.LogInformation($"[InitiateTrade] Blocktrade reply: {JsonConvert.SerializeObject(r1, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })}");

            var objTrans = new Transactions();

            //if (amount.HasValue)
            //{
            //    objTrans.Amount = amount.Value;
            //}

            objTrans.Cryptoconfirmed = false;

            objTrans.Cryptoaddress  = r1.InputAddress;
            objTrans.Cryptocurrency = r1.InputCoinType;
            objTrans.Memobc         = memoGuid;

            objTrans.Modifiedby = "System";
            objTrans.Createdby  = "System";
            objTrans.Createdon  = now;
            objTrans.Modifiedon = now;

            await _transRepository.AddAsync(objTrans);

            var error1 = _unitOfWork.CommitHandled();

            if (!error1)
            {
                _logger.LogError($"Can't Add Transaction ! {JsonConvert.SerializeObject(error1, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            _logger.LogInformation($"[InitiateTrade] Transaction created in DB: {JsonConvert.SerializeObject(objTrans, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })}");

            var guidString = Guid.NewGuid().ToString();
            await _commonMessageService.SendMessage <ActionEventDefinition>("llc-event-broadcast", guidString,
                                                                            new ActionEventDefinition()
            {
                ActionName = "InitiateTradeTriggered",
                Message    = string.Format($"New participation initiated => {objTrans.Transactionid} => {r1.InputAddress}"),
                Timestamp  = DateTime.UtcNow,
                Success    = true,
                Reason     = "Subscription"
            });

            return(r1);
        }
Exemple #2
0
        public async Task <TD> CreateAsync(TD pDto, Func <T, bool> keyPredicate)
        {
            Check.Require(pDto != null, "entity must be valid.");

            var now = DateTime.UtcNow;

            var p0 = new T();

            var p = _mapper.Map <TD, T>(pDto, p0);

            p.Createdon  = now;
            p.Modifiedon = now;
            p.Createdby  = "System";
            p.Modifiedby = "System";

            var up1 = await _genRepository.AddAsync(p);

            var errors = await _unitOfWork.CommitHandledAsync();

            if (!errors)
            {
                _logger.LogError($"Can't create ! {JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            return(_mapper.Map <T, TD>(up1));
        }
        public async Task <User> CreateUser(CustomerCreateOrUpdate info)
        {
            Check.Require(info != null, "CustomerCreateOrUpdate must be valid.");

            var now = DateTime.UtcNow;

            var u = _mapper.Map <CustomerCreateOrUpdate, User>(info);

            u.Createdon  = now;
            u.Modifiedon = now;
            u.Createdby  = "System";
            u.Modifiedby = "System";

            var peEntity = await CreatePeople(info);

            u.People = peEntity;

            u.Activate = true;

            await _userRepository.AddAsync(u);

            var errors = await _unitOfWork.CommitHandledAsync();

            if (!errors)
            {
                _logger.LogError($"Can't create user ! { JsonConvert.SerializeObject(u, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            return(u);
        }
Exemple #4
0
        public async Task <Address> CreateAddress(People p, CustomerCreateOrUpdate info)
        {
            Check.Require(info != null, "CustomerCreateOrUpdate must be valid.");

            var now = DateTime.UtcNow;

            var add1 = new Address()
            {
                People     = p,
                Street1    = info.Address1,
                Street2    = info.Address2,
                Country    = info.Country,
                Modifiedon = now,
                Createdby  = "System",
                Modifiedby = "System",
                Createdon  = now
            };

            await _addressRepository.AddAsync(add1);

            var errors = await _unitOfWork.CommitHandledAsync();

            if (!errors)
            {
                _logger.LogError($"Can't create address ! {JsonConvert.SerializeObject(add1, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            return(add1);
        }
Exemple #5
0
        public async Task <People> CreatePeople(CustomerCreateOrUpdate info)
        {
            Check.Require(info != null, "CustomerCreateOrUpdate must be valid.");

            var now = DateTime.UtcNow;

            var p = new People();

            p.Firstname  = info.FirstName;
            p.Lastname   = info.LastName;
            p.Email      = info.Email;
            p.Createdon  = now;
            p.Modifiedon = now;
            p.Createdby  = "System";
            p.Modifiedby = "System";

            await _peopleRepository.AddAsync(p);

            var errors = await _unitOfWork.CommitHandledAsync();

            if (!errors)
            {
                _logger.LogError($"Can't create people ! {JsonConvert.SerializeObject(p, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            return(p);
        }
        private async Task <Tuple <Genericattributetype, Genericattributevalue> > CreateOrGetTupleTypeValue(
            string type,
            string value,
            object typeObject  = null,
            object valueObject = null,
            int typeSort       = 0,
            int valueSort      = 0,
            int?categoryId     = null)
        {
            //var res = "";

            //TypeSwitch.Do(
            //    value,
            //    TypeSwitch.Case<sbyte>(() => res = "It's a int"),
            //    TypeSwitch.Case<byte>(x => res = "It's a long"),
            //    TypeSwitch.Case<short>(x => res = "It's a long"),
            //    TypeSwitch.Case<ushort>(x => res = "It's a long"),
            //    TypeSwitch.Case<int>(x => res = "It's a long"),
            //    TypeSwitch.Case<uint>(x => res = "It's a long"),
            //    TypeSwitch.Case<long>(x => res = "It's a long"),
            //    TypeSwitch.Case<ulong>(x => res = "It's a long"),
            //    TypeSwitch.Case<char>(x => res = "It's a long"),
            //    TypeSwitch.Case<float>(x => res = "It's a long"),
            //    TypeSwitch.Case<double>(x => res = "It's a long"),
            //    TypeSwitch.Case<bool>(x => res = "It's a long"),
            //    TypeSwitch.Case<decimal>(x => res = "It's a long"),
            //    TypeSwitch.Case<string>(x => res = "It's a long"),
            //    TypeSwitch.Case<DateTime>(x => res = "It's a long"),
            //    TypeSwitch.Default(() => res = "It's default"));

            var utcNow = DateTime.UtcNow;

            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.All,
            };

            settings.Converters.Insert(0, new PrimitiveJsonConverter());


            var typeEntity  = new Genericattributetype();
            var valueEntity = new Genericattributevalue();

            typeEntity.Createdon  = utcNow;
            typeEntity.Modifiedon = utcNow;
            typeEntity.Createdby  = "System";
            typeEntity.Modifiedby = "System";

            valueEntity.Createdon  = utcNow;
            valueEntity.Modifiedon = utcNow;
            valueEntity.Createdby  = "System";
            valueEntity.Modifiedby = "System";

            typeEntity.Sort  = typeSort;
            valueEntity.Sort = valueSort;

            typeEntity.Name = type;

            if (categoryId.HasValue)
            {
                typeEntity.Categoryid = categoryId.Value;
            }

            if (typeObject != null)
            {
                var typeObjectJson = JsonConvert.SerializeObject(typeObject, settings);
                typeEntity.Valuestring = typeObjectJson;

                typeEntity.Metatypestring = typeObject.GetType().Name;
                typeEntity.Metatypelabel  = typeObject.GetType().AssemblyQualifiedName;
            }

            valueEntity.Name = value;

            if (valueObject != null)
            {
                var valueObjectJson = JsonConvert.SerializeObject(valueObject, settings);
                valueEntity.Valuestring = valueObjectJson;

                valueEntity.Metatypestring = valueObject.GetType().Name;
                valueEntity.Metatypelabel  = valueObject.GetType().AssemblyQualifiedName;
            }

            Genericattributetype  finalType;
            Genericattributevalue finalValue;

            var findType = _attributeTypeRepository.DbSet.FirstOrDefault(
                x => x.Categoryid == typeEntity.Categoryid &&
                x.Name == typeEntity.Name &&
                x.Valuestring == typeEntity.Valuestring &&
                x.Metatypestring == typeEntity.Metatypestring &&
                x.Metatypelabel == typeEntity.Metatypelabel);

            if (findType != null)
            {
                finalType = findType;
            }
            else
            {
                await _attributeTypeRepository.AddAsync(typeEntity);

                var errors1 = await _unitOfWork.CommitHandledAsync();

                if (!errors1)
                {
                    _logger.LogError($"Can't Attribute Type ! {JsonConvert.SerializeObject(typeEntity, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
                }

                finalType = typeEntity;
            }

            var findValue = _attributeValueRepository.DbSet.FirstOrDefault(
                x => x.Name == valueEntity.Name &&
                x.Valuestring == valueEntity.Valuestring &&
                x.Metatypestring == valueEntity.Metatypestring &&
                x.Metatypelabel == valueEntity.Metatypelabel);

            if (findValue != null)
            {
                finalValue = findValue;
            }
            else
            {
                await _attributeValueRepository.AddAsync(valueEntity);

                var errors2 = await _unitOfWork.CommitHandledAsync();

                if (!errors2)
                {
                    _logger.LogError($"Can't Attribute Value ! {JsonConvert.SerializeObject(valueEntity, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
                }

                finalValue = valueEntity;
            }

            var resTuple = new Tuple <Genericattributetype, Genericattributevalue>(finalType, finalValue);

            return(resTuple);
        }
        public async Task <Genericattribute> CreateOrGetAttribute(
            string type,
            string value,
            object typeObject  = null,
            object valueObject = null,
            int typeSort       = 0,
            int valueSort      = 0,
            int?categoryId     = null)
        {
            Check.Require(!string.IsNullOrWhiteSpace(type), "type must be supplied.");
            Check.Require(!string.IsNullOrWhiteSpace(value), "value must be supplied.");

            var utcNow = DateTime.UtcNow;

            var tupleTypeValue = await CreateOrGetTupleTypeValue(type, value, typeObject, valueObject, typeSort, valueSort, categoryId);

            var findAttribute = _attributeRepository.DbSet.FirstOrDefault(x => x.Genericattributetypeid == tupleTypeValue.Item1.Genericattributetypeid &&
                                                                          x.Genericattributevalueid == tupleTypeValue.Item2.Genericattributevalueid);

            if (findAttribute != null)
            {
                return(findAttribute);
            }

            var attribute = new Genericattribute();

            attribute.Genericattributetypeid  = tupleTypeValue.Item1.Genericattributetypeid;
            attribute.Genericattributevalueid = tupleTypeValue.Item2.Genericattributevalueid;

            attribute.Typestring  = type;
            attribute.Valuestring = value;

            attribute.Createdon  = utcNow;
            attribute.Modifiedon = utcNow;
            attribute.Createdby  = "System";
            attribute.Modifiedby = "System";

            JsonSerializerSettings settings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.All,
            };

            settings.Converters.Insert(0, new PrimitiveJsonConverter());

            if (typeObject != null)
            {
                attribute.Typelabelstring = JsonConvert.SerializeObject(typeObject, settings);
            }
            else
            {
                attribute.Typelabelstring = EncodeLabel(type);
            }

            if (valueObject != null)
            {
                attribute.Valuelabelstring = JsonConvert.SerializeObject(valueObject, settings);
            }
            else
            {
                attribute.Valuelabelstring = EncodeLabel(value);
            }

            await _attributeRepository.AddAsync(attribute);

            var error1 = _unitOfWork.CommitHandled();

            if (!error1)
            {
                _logger.LogError($"Can't Attribute ! {JsonConvert.SerializeObject(attribute, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} ");
            }

            return(attribute);
        }