public ActionResult EditAccount(int id)
        {
            AccountData accountData = new AccountData();
            AccountRepository accountRepository = new AccountRepository();
            var account = accountRepository.GetAccountById(id);

            if (account != null)
                accountData = account;

            return View("EditAccount", account);
        }
        public bool AddAcount(AccountData account)
        {
            using (var ctx = new forexBox2Entities())
            {
                ctx.AccountDatas.AddObject(account);

                try
                {
                    ctx.SaveChanges();
                }
                catch { return false; }
            }

            return true;
        }
 /// <summary>
 /// Create a new AccountData object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 public static AccountData CreateAccountData(global::System.Int32 id, global::System.Guid userId)
 {
     AccountData accountData = new AccountData();
     accountData.Id = id;
     accountData.UserId = userId;
     return accountData;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the AccountDatas EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAccountDatas(AccountData accountData)
 {
     base.AddObject("AccountDatas", accountData);
 }
        public ActionResult SaveAccount(AccountData account)
        {
            if (account != null)
            {
                AccountRepository accountRepository = new AccountRepository();
                if (account.Id == 0)
                {
                    UsersRepository repository = new UsersRepository();
                    var user = repository.GetUserByLoginName(User.Identity.Name);
                    if (user != null)
                        account.UserId = user.UserId;
                    accountRepository.AddAcount(account);
                }
                else accountRepository.SaveAcount(account);
            }

            return RedirectToAction("ManageAccounts");
        }
        public bool SaveAcount(AccountData account)
        {
            using (var ctx = new forexBox2Entities())
            {
                var existAccount = ctx.AccountDatas.FirstOrDefault(x => x.Id == account.Id);
                if (existAccount != null)
                {
                    existAccount.Broker = account.Broker;
                    existAccount.Leverage = account.Leverage;
                    existAccount.System = account.System;
                    existAccount.Technical = account.Technical;
                    existAccount.Trading = account.Trading;
                    existAccount.Type = account.Trading;
                    existAccount.Desctiption = account.Desctiption;

                    try
                    {
                        ctx.SaveChanges();
                    }
                    catch { return false; }
                }
            }

            return true;
        }