예제 #1
0
        public void UpdateMargin(List <Margin> lstMargin)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var marginRepo =
                        new MarginRepository(new EFRepository <Margin>(), unitOfWork);


                    ObjectSet <Margin> marginObj =
                        ((CurrentDeskClientsEntities)marginRepo.Repository.UnitOfWork.Context).Margins;

                    var lstLogin = lstMargin.Select(m => m.Login).ToList();
                    //Get the existing margins from DB and update with New DB
                    var lstDBMargin = marginObj.Where(m => lstLogin.Contains(m.Login)).ToList();
                    foreach (var uMargin in lstDBMargin)
                    {
                        var newMargin = lstMargin.Where(m => m.Login == uMargin.Login).FirstOrDefault();
                        if (newMargin != null)
                        {
                            uMargin.Login       = newMargin.Login;
                            uMargin.Group       = newMargin.Group;
                            uMargin.Leverage    = newMargin.Leverage;
                            uMargin.Updated     = newMargin.Updated;
                            uMargin.Balance     = newMargin.Balance;
                            uMargin.Equity      = newMargin.Equity;
                            uMargin.Volume      = newMargin.Volume;
                            uMargin.Margin1     = newMargin.Margin1;
                            uMargin.MarginFree  = newMargin.MarginFree;
                            uMargin.MarginLevel = newMargin.MarginLevel;
                            uMargin.MarginType  = newMargin.MarginType;
                            uMargin.LevelType   = newMargin.LevelType;
                        }
                    }

                    //Add new price
                    var lstDBLogin      = lstDBMargin.Select(p => p.Login).ToList();
                    var newMarginsToAdd = lstMargin.Where(lp => !lstDBLogin.Contains(lp.Login)).ToList();
                    foreach (var marin in newMarginsToAdd)
                    {
                        marginRepo.Add(marin);
                    }

                    marginRepo.Save();
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }
예제 #2
0
        // Add your own data access methods here.  If you wish to
        // expose your public method to a WCF service, marked them with
        // the attribute [NCPublish], and another T4 template will generate your service contract



        public void UpdateMargin(Margin newMargin)
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var marginRepo =
                        new MarginRepository(new EFRepository <Margin>(), unitOfWork);


                    ObjectSet <Margin> marginObj =
                        ((CurrentDeskClientsEntities)marginRepo.Repository.UnitOfWork.Context).Margins;


                    //Check existing margin
                    var dbMargin = marginObj.Where(m => m.Login == newMargin.Login).FirstOrDefault();
                    if (dbMargin == null)
                    {
                        marginRepo.Add(newMargin);
                    }
                    else
                    {
                        dbMargin.Login       = newMargin.Login;
                        dbMargin.Group       = newMargin.Group;
                        dbMargin.Leverage    = newMargin.Leverage;
                        dbMargin.Updated     = newMargin.Updated;
                        dbMargin.Balance     = newMargin.Balance;
                        dbMargin.Equity      = newMargin.Equity;
                        dbMargin.Volume      = newMargin.Volume;
                        dbMargin.Margin1     = newMargin.Margin1;
                        dbMargin.MarginFree  = newMargin.MarginFree;
                        dbMargin.MarginLevel = newMargin.MarginLevel;
                        dbMargin.MarginType  = newMargin.MarginType;
                        dbMargin.LevelType   = newMargin.LevelType;
                    }

                    marginRepo.Save();
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }