public void ChangeParameters(ParametersChangeModel masterParameters, List <ParametersChangeModel> investorsAmount, DateTime datePreviousProcessing, DateTime dateNextProcessing) { using (var db = GetDBConnect()) { db.BeginTransaction(); db._master_accounts .Where(master => master.trading_account_id == masterParameters.Id) .Set(master => master.amount_own, masterParameters.AmountOwn) .Set(master => master.status, (short)masterParameters.NewAccountStatus) .Set(master => master.percent, masterParameters.Percent) .Set(master => master.date_next_processing, dateNextProcessing) .Set(master => master.date_previous_processing, datePreviousProcessing) .Set(master => master.date_close, masterParameters.NewAccountStatus == AccountStatus.Out ? DateTime.Now : DateTime.MinValue) .Update(); foreach (var inv in investorsAmount) { var isdeleting = inv.NewAccountStatus == AccountStatus.Out; db._investor_accounts .Where(investor => investor.id == inv.Id) .Set(investor => investor.amount, inv.AmountOwn) .Set(investor => investor.status, (short)inv.NewAccountStatus) .Set(investor => investor.percent, inv.Percent) .Set(investor => investor.isdeleted, isdeleting) .Set(investor => investor.date_disconnect_accepted, isdeleting ? DateTime.Now : DateTime.MinValue) .Set(investor => investor.date_connect_accepted, inv.PrevAccountStatus == AccountStatus.PendingIn ? DateTime.Now : DateTime.MinValue) .Update(); } db.CommitTransaction(); } }
//Calculate new values for AmountOwn and AccountStatus + process withdrawal private ParametersChangeModel NextPeriodParametersCalculation(long accountId, AccountStatus accountStatus, long walletId, decimal amountOwn, decimal investmentAmount, bool isMaster) { var changeModel = new ParametersChangeModel { Id = accountId, AmountOwn = amountOwn, PrevAccountStatus = accountStatus, NewAccountStatus = accountStatus == AccountStatus.In || accountStatus == AccountStatus.PendingIn ? AccountStatus.In : AccountStatus.Out }; changeModel.AmountOwn += investmentAmount; //delete investors with 0 if (!isMaster && changeModel.AmountOwn == 0) { changeModel.NewAccountStatus = AccountStatus.Out; } return(changeModel); }