Beispiel #1
0
        internal static Command CreateAccountUpdateCommand(this Account account)
        {
            AccountUpdateCommand accountUpdateCommand = new AccountUpdateCommand();

            accountUpdateCommand.AccountID = account.Id;
            accountUpdateCommand.Content   = account.ToXml(new XmlParameter(false, false, false)).ToXmlNode();
            return(accountUpdateCommand);
        }
Beispiel #2
0
        private static Command CreateOrderChangedCommand(this OrderChange orderChange)
        {
            AccountUpdateCommand accountUpdateCommand = null;
            Order order = (Order)orderChange.Source;

            if ((order.Owner.InstrumentCategory == InstrumentCategory.Physical || order.LotBalance > 0) && order.Phase == OrderPhase.Executed && orderChange.PropertyType != PropertyChangeType.None)
            {
                XmlDocument xmlDoc = new XmlDocument();
                if (accountUpdateCommand == null)
                {
                    accountUpdateCommand           = new AccountUpdateCommand();
                    accountUpdateCommand.AccountID = order.Account.Id;
                    accountUpdateCommand.Content   = xmlDoc.CreateElement("Orders");
                }

                XmlElement orderNode = xmlDoc.CreateElement("Order");

                orderNode.SetAttribute("ID", XmlConvert.ToString(order.Id));
                if (orderChange.PropertyType.Contains(PropertyChangeType.AutoLimitPrice))
                {
                    string autoLimitPrice = (order.AutoLimitPrice == null ? "" : (string)order.AutoLimitPrice);
                    orderNode.SetAttribute("AutoLimitPrice", autoLimitPrice);
                }
                if (orderChange.PropertyType.Contains(PropertyChangeType.AutoStopPrice))
                {
                    string autoStopPrice = (order.AutoStopPrice == null ? "" : (string)order.AutoStopPrice);
                    orderNode.SetAttribute("AutoStopPrice", autoStopPrice);
                }
                if (orderChange.PropertyType.Contains(PropertyChangeType.PaidPledgeBalance))
                {
                    orderNode.SetAttribute("PaidPledgeBalance", XmlConvert.ToString(order.PaidPledgeBalance));
                }
                if (orderChange.PropertyType.Contains(PropertyChangeType.PaidPledge))
                {
                    orderNode.SetAttribute("PaidPledge", XmlConvert.ToString(order.PaidPledge));
                }
                if (orderChange.PropertyType.Contains(PropertyChangeType.HasOverdue))
                {
                    orderNode.SetAttribute("IsInstalmentOverdue", XmlConvert.ToString(order.IsInstalmentOverdue));
                }
                accountUpdateCommand.Content.AppendChild(orderNode);
            }
            return(accountUpdateCommand);
        }
        public async Task <CommandResponse> Handle(AccountUpdateCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                return(request.CommandResponse);
            }

            var checkAccount = await _accountRepository.FindById(request.Id);

            if (checkAccount == null)
            {
                request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure("", "Account Id Not Found."));
                return(request.CommandResponse);
            }


            if (checkAccount.Email != request.Email)
            {
                if (await _accountRepository.EmailExists(request.Email))
                {
                    request.CommandResponse.ValidationResult.Errors.Add(new ValidationFailure("", "E-mail already exists."));
                    return(request.CommandResponse);
                }
            }

            var account = new Account(request.Id, request.Name, request.SurName, request.Email,
                                      checkAccount.PasswordHash, checkAccount.PasswordSalt, DateTime.Now);

            account.Apply(new AccountUpdateEvent(account.Id, account.Name, account.Surname, account.Email));

            _accountRepository.Update(account);

            await _eventStoreRepository.SaveAsync <Account>(account);

            return(await Commit(_accountRepository.UnitOfWork));
        }