public AccountFormView()
 {
     DevExpress.XamarinForms.Editors.Initializer.Init();
     InitializeComponent();
     viewModel      = new AccountFormViewModel();
     BindingContext = viewModel;
 }
예제 #2
0
        //Display Filled User Form
        public async Task <IActionResult> Update(string id)
        {
            var account = await _userManager.FindByIdAsync(id);

            if (account == null)
            {
                return(NotFound());
            }

            if (User.Identity.Name == account.UserName || User.IsInRole("Admin"))
            {
                var viewModel = new AccountFormViewModel()
                {
                    Id          = account.Id,
                    Heading     = $"Edit {account.FirstName} {account.LastName}",
                    FirstName   = account.FirstName,
                    LastName    = account.LastName,
                    Gender      = account.Gender,
                    DateOfBirth = account.DateOfBirth
                };

                return(View("UserForm", viewModel));
            }

            return(View("User"));
        }
예제 #3
0
        public IActionResult EditAccount(AccountFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Account.TargetID = _targetAmountRepo.TargetAmounts.Where(x => x.TypeID == model.SelectedTarget).First().ID;
                _accountRepo.Save(model.Account);
                TempData["message"] = $"Account #{model.Account.ID} has been saved";
                return(RedirectToAction("Accounts"));
            }
            else
            {
                if (model.Account.ID == 0)
                {
                    ViewBag.FormTitle = "Create Account";
                }
                else
                {
                    ViewBag.FormTitle = "Edit Account";
                }

                model.AccountTypes = new SelectList(_accountTypeRepo.AccountTypes.ToList(), "ID", "Name");
                model.TargetTypes  = new SelectList(_targetTypeRepo.TargetTypes.ToList(), "ID", "Name");
                return(View(model));
            }
        }
        public ActionResult Edit(int id)
        {
            Account account = Context.Accounts.Single(a => a.Id == id);
            User    user    = Context.Users.Single(u => u.Id == account.UserId);

            string pin = Interaction.InputBox("Enter PIN to edit the account.",
                                              "Edit account", "", 1, 1);

            if (pin.Equals(user.Pin))
            {
                AccountFormViewModel afvm = new AccountFormViewModel
                {
                    Mode      = "Edit",
                    AccountId = id,
                    UserLogin = user.Login,
                    Title     = account.Title,
                    Login     = account.Login,
                    Email     = account.Email,
                    Password  = account.Password
                };

                return(View("AccountForm", afvm));
            }
            else
            {
                MainViewModel mvm = new MainViewModel
                {
                    Login    = user.Login,
                    Accounts = Context.Accounts.Where(a => a.UserId == id).ToList()
                };

                MessageBox.Show("Invalid pin.", "Error");
                return(RedirectToAction("Index", mvm));
            }
        }
예제 #5
0
        public ActionResult Save(Account account)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new AccountFormViewModel
                {
                    Account      = account,
                    ConsoleTypes = _context.ConsoleTypes.ToList()
                };

                return(View("AccountForm", viewModel));
            }

            if (account.AccountID == 0)
            {
                _context.Accounts.Add(account);
            }
            else
            {
                var accountInDb = _context.Accounts.Single(a => a.AccountID == account.AccountID);

                accountInDb.AName = account.AName;
                accountInDb.IsSubcribedOnEpicGames = account.IsSubcribedOnEpicGames;
                accountInDb.ConsoleTypeID          = account.ConsoleTypeID;
            }

            _context.SaveChanges();
            return(RedirectToAction("Index", "Accounts"));
        }
예제 #6
0
        public ActionResult Save(AccountFormViewModel accountViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("AccountForm", accountViewModel));
            }
            //else continue with new or update account
            if (accountViewModel.AccountDto.Id == 0)//means it's new
            {
                var account = Mapper.Map <AccountDto, Account>(accountViewModel.AccountDto);
                _context.Accounts.Add(account);
                _context.SaveChanges();
            }
            else
            {
                var accountInDb = _context.Accounts.Find(accountViewModel.AccountDto.Id);
                if (accountInDb == null)
                {
                    return(HttpNotFound());
                }
                Mapper.Map(accountViewModel.AccountDto, accountInDb);
                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
예제 #7
0
        //Display Empty User Form
        public IActionResult Create()
        {
            var accountForm = new AccountFormViewModel {
                Heading = "Create a new User"
            };

            return(View("UserForm", accountForm));
        }
예제 #8
0
        public ActionResult New()
        {
            var ConsoleType = _context.ConsoleTypes.ToList();
            var ViewModel   = new AccountFormViewModel
            {
                Account      = new Account(),
                ConsoleTypes = ConsoleType
            };

            return(View("AccountForm", ViewModel));
        }
예제 #9
0
        public ActionResult Edit(int id)
        {
            var accountInDb = _context.Accounts.Find(id);
            var accountDto  = Mapper.Map <Account, AccountDto>(accountInDb);

            var accountViewModel = new AccountFormViewModel
            {
                ActionIndicator = 2,
                AccountDto      = accountDto,
                AccountMasters  = _context.AccountMasters.ToList(),
                Accounts        = _context.Accounts.ToList(),
                Currencies      = _context.DbCurrencies.ToList()
            };

            return(View("AccountForm", accountViewModel));
        }
예제 #10
0
        public ActionResult Edit(int id)
        {
            var account = _context.Accounts.SingleOrDefault(a => a.AccountID == id);

            if (account == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new AccountFormViewModel
            {
                Account      = account,
                ConsoleTypes = _context.ConsoleTypes.ToList()
            };

            return(View("AccountForm", viewModel));
        }
예제 #11
0
        public ActionResult New()
        {
            var accountDto = new AccountDto
            {
                Id = 0
            };

            var accountsViewModel = new AccountFormViewModel
            {
                ActionIndicator = 1,
                AccountDto      = accountDto,
                AccountMasters  = _context.AccountMasters.ToList(),
                Accounts        = _context.Accounts.ToList(),
                Currencies      = _context.DbCurrencies.ToList()
            };

            return(View("AccountForm", accountsViewModel));
        }
예제 #12
0
        public async Task <IActionResult> Create(AccountFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserForm", viewModel));
            }

            //Create new user
            var account = new UserAccount
            {
                FirstName   = viewModel.FirstName,
                LastName    = viewModel.LastName,
                Gender      = viewModel.Gender,
                DateOfBirth = viewModel.DateOfBirth,
            };

            await _userManager.CreateAsync(account);

            return(RedirectToAction("Index", "Home"));
        }
예제 #13
0
        public async Task <IActionResult> Update(AccountFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("UserForm", viewModel));
            }

            //Update existing User
            var accountInDb = await _userManager.FindByIdAsync(viewModel.Id.ToString());

            if (accountInDb == null)
            {
                return(NotFound());
            }

            accountInDb.FirstName   = viewModel.FirstName;
            accountInDb.LastName    = viewModel.LastName;
            accountInDb.Gender      = viewModel.Gender;
            accountInDb.DateOfBirth = viewModel.DateOfBirth;

            await _userManager.UpdateAsync(accountInDb);

            return(RedirectToAction("Index", "Home"));
        }
 public DataFormAccountFormView()
 {
     DevExpress.XamarinForms.DataForm.Initializer.Init();
     InitializeComponent();
     BindingContext = new AccountFormViewModel();
 }