Beispiel #1
0
        public async Task <ActionResult <Client_Account> > PostClient_Account(Client_Account client_Account)
        {
            _context.ClientAccountTable.Add(client_Account);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetClient_Account", new { id = client_Account.ID }, client_Account));
        }
Beispiel #2
0
        public async Task <IActionResult> PutClient_Account(int id, Client_Account client_Account)
        {
            if (id != client_Account.ID)
            {
                return(BadRequest());
            }

            _context.Entry(client_Account).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Client_AccountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
 public void Add(Client_Account entity)
 {
     Repository.Add(entity);
 }
Beispiel #4
0
 public void Delete(Client_Account entity)
 {
     Repository.Delete(entity);
 }
        /// <summary>
        /// Added Client Records for Migrated users
        /// </summary>
        public void AddClientRecord()
        {
            try
            {
                using (var unitOfWork = new EFUnitOfWork())
                {
                    var userRecordRepo = new UserRecordRepository(new EFRepository <UserRecord>(), unitOfWork);


                    var context = (CurrentDeskClientsEntities)unitOfWork.Context;

                    //2 is used for grouping
                    int cnt = 0;
                    while (cnt <= GroupType)
                    {
                        List <UserRecord>      lstUserRecordsDB = new List <UserRecord>();
                        List <GroupUserRecord> lstUserRecordGrp = null;

                        if (cnt == 0)
                        {
                            //Get All UserRecords from DB
                            lstUserRecordsDB = (from u in context.UserRecords
                                                let ur = from em in context.Users select em.UserEmailID
                                                         where ur.Contains(u.Email) == false && !(u.Email == null || u.Email.Equals(""))
                                                         select u).ToList();


                            //Group userrecords by Name,Email and Address
                            var lstUserRecordGrpTemp = lstUserRecordsDB.GroupBy(cm => new { cm.Email },
                                                                                (key, group) => new
                            {
                                Email = key.Email
                            }).ToList();

                            //Create list by adding name and address
                            lstUserRecordGrp = (from email in lstUserRecordGrpTemp
                                                select new GroupUserRecord
                            {
                                Email = email.Email,
                                Address = string.Empty,
                                Name = string.Empty
                            }).ToList();
                        }
                        else
                        {
                            lstUserRecordsDB = (from u in context.UserRecords
                                                let ur = from em in context.Client_Account where em.IsTradingAccount == true select em.PlatformLogin
                                                         where ur.Contains(u.Login) == false && (u.Email == null || u.Email.Equals(""))
                                                         select u).ToList();

                            //Get all User without email
                            //lstUserRecordsDB = (from u in context.UserRecords
                            //                    where (u.Email == null || u.Email.Equals(""))
                            //                    select u).ToList();


                            //Group userrecords by Name,Email and Address
                            var lstUserRecordGrpTempName = lstUserRecordsDB.GroupBy(cm => new { cm.Name, cm.Address },
                                                                                    (key, group) => new
                            {
                                Name    = key.Name,
                                Address = key.Address
                            }).ToList();

                            lstUserRecordGrp = (from email in lstUserRecordGrpTempName
                                                select new GroupUserRecord
                            {
                                Email = string.Empty,
                                Address = email.Address,
                                Name = email.Name
                            }).ToList();
                        }


                        // var uniqueClientRecord = lstUserRecordGrp.Where(g => g.Count == 1).ToList();
                        foreach (var clientrecord in lstUserRecordGrp)
                        {
                            var clientRecordsDB = new List <UserRecord>();
                            if (cnt == 0)
                            {
                                //Get the records from DB list
                                clientRecordsDB = lstUserRecordsDB.Where(u => u.Email == clientrecord.Email).ToList();
                            }
                            else
                            {
                                clientRecordsDB = lstUserRecordsDB.Where(u => u.Address == clientrecord.Address && u.Name == clientrecord.Name).ToList();
                            }

                            //Get the first account for Client Table
                            var firstAccount = clientRecordsDB.First();


                            //Create password
                            User user = new User
                            {
                                UserEmailID   = string.IsNullOrEmpty(firstAccount.Email) ? "mu" + firstAccount.Login + "@bo.com" : firstAccount.Email,
                                Password      = new Common.CurrentDeskSecurity().SetPassEncrypted("mu" + firstAccount.Login),
                                FK_UserTypeID = Constants.K_BROKER_LIVE
                            };

                            Client client = new Client
                            {
                                FK_AccountID         = Common.Constants.K_TRADING_ACCOUNT,
                                FK_AccountTypeID     = Common.Constants.K_LIVE_INDIVIDUAL,
                                FK_TradingPlatformID = Common.Constants.K_META_TRADER,
                                FK_AccountCurrencyID = 7
                            };

                            int countryId = (from c in context.L_Country
                                             where c.CountryName.Trim() == firstAccount.Country.Trim()
                                             select c.PK_CountryID
                                             ).FirstOrDefault();

                            if (countryId == 0)
                            {
                                countryId = 1;
                            }

                            IndividualAccountInformation iac = new IndividualAccountInformation
                            {
                                FirstName          = firstAccount.Name,
                                ResidentialAddress = firstAccount.Address,
                                EmailAddress       = firstAccount.Email,
                                TelephoneNumber    = firstAccount.Phone,
                                IDNumber           = firstAccount.ID,
                                Client             = client,

                                FK_ResidenceCountryID          = countryId,
                                FK_CitizenShipCountryID        = countryId,
                                FK_ResidentialAddressCountryID = countryId,


                                ResidentialAddressCity       = firstAccount.City,
                                ResidentialAddressPostalCode = firstAccount.ZipCode,
                                State   = firstAccount.State,
                                Status  = firstAccount.Status,
                                Agent   = Convert.ToString(firstAccount.AgentAccount),
                                TaxRate = firstAccount.Taxes
                            };

                            client.IndividualAccountInformations.Add(iac);
                            user.Clients.Add(client);
                            context.Users.AddObject(user);

                            context.SaveChanges();


                            string landingAcn = string.Empty;
                            string tradingAcn = string.Empty;
                            long   lAccountNo = 0;
                            CreateAccountNumberForUser(client, out tradingAcn, out landingAcn, out lAccountNo);


                            Client_Account clientAccountLanding = new Client_Account
                            {
                                AccountNumber    = lAccountNo,
                                LandingAccount   = landingAcn,
                                FK_CurrencyID    = 5,
                                IsLandingAccount = true,
                                IsTradingAccount = false
                            };

                            client.Client_Account.Add(clientAccountLanding);

                            foreach (var crb in clientRecordsDB)
                            {
                                var            equity = context.Margins.Where(l => l.Login == crb.Login).Select(m => m.Equity).FirstOrDefault();
                                Client_Account clientAccountTrading = new Client_Account
                                {
                                    AccountNumber    = lAccountNo,
                                    LandingAccount   = landingAcn,
                                    TradingAccount   = tradingAcn,
                                    CurrentBalance   = Convert.ToDecimal(crb.Balance),
                                    PlatformLogin    = crb.Login,
                                    PlatformPassword = crb.Password,
                                    FK_CurrencyID    = 5,

                                    Group            = crb.Group,
                                    Leverage         = Convert.ToString(crb.Leverage),
                                    Credit           = Convert.ToDecimal(crb.Credit),
                                    Equity           = equity,
                                    Comment          = crb.Comment,
                                    IsTradingAccount = true,
                                    IsLandingAccount = false
                                };


                                client.Client_Account.Add(clientAccountTrading);

                                context.SaveChanges();

                                var newLandingAC = string.Empty;
                                tradingAcn = string.Empty;
                                lAccountNo = 0;
                                CreateAccountNumberForUser(client, out tradingAcn, out newLandingAC, out lAccountNo);
                            }
                        }

                        //Increment
                        cnt++;
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorLogger.CommonErrorLog(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
            }
        }