示例#1
0
        private void FieldMap(AccountPosition pos, account_positions posDB)
        {
            posDB.id = pos.Id;
            if (pos.Account != null)
            {
                posDB.account_id = pos.Account.Id;
            }

            if (pos.Security != null)
            {
                posDB.symbol = pos.Security.Symbol;
            }

            posDB.weight       = pos.Weight;
            posDB.shares       = pos.Shares;
            posDB.market_price = pos.MarketPrice;
            posDB.ammount      = pos.Ammount;

            if (pos.PositionStatus != null)
            {
                posDB.status = pos.PositionStatus.Code.ToString();
            }

            posDB.active = pos.Active;
        }
示例#2
0
        public void Persist(Instruction instr)
        {
            //Insert
            if (instr.Id == 0)
            {
                instructions instrDB = Map(instr);
                ctx.instructions.AddObject(instrDB);

                if (instr.AccountPosition != null)
                {
                    account_positions posDB = ctx.account_positions.Where(x => x.id == instr.AccountPosition.Id).FirstOrDefault();
                    FieldMap(instr.AccountPosition, posDB);
                }

                ctx.SaveChanges();
                instr.Id = instrDB.id;
            }
            else
            {
                instructions instrDB = ctx.instructions.ToList().Where(x => x.id == instr.Id).FirstOrDefault();
                FieldMap(instr, instrDB);

                if (instr.AccountPosition != null && instr.AccountPosition.Account != null)
                {
                    account_positions posDB = ctx.account_positions.Where(x => x.id == instr.AccountPosition.Id).FirstOrDefault();
                    FieldMap(instr.AccountPosition, posDB);
                }

                ctx.SaveChanges();
            }
        }