Exemplo n.º 1
0
        public ActionResult Edit(int id, AccountEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.AccountId != id)
            {
                ModelState.AddModelError("", "ID does not match");
                return(View(model));
            }

            var svc = CreateAccountService();

            if (svc.UpdateAccount(model))
            {
                TempData["SaveResult"] = "Your Account Has Been Updated";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Account Could Not Be Updated");

            return(View());
        }
Exemplo n.º 2
0
        public async Task <ActionResult> EditUser(AccountEdit user)
        {
            UserAPI apiUser = new UserAPI();

            apiUser.Username = user.newUsername ?? user.Username;
            apiUser.Email    = user.newEmail;
            apiUser.Created  = user.Created;
            apiUser.Modified = user.Modified;
            apiUser.Id       = user.Id;

            // Edit User
            HttpRequestMessage apiRequest = CreateRequestToService(HttpMethod.Put, "Users");

            apiRequest.Content = new ObjectContent <UserAPI>(apiUser, new JsonMediaTypeFormatter());

            HttpResponseMessage apiResponse;

            try
            {
                apiResponse = await HttpClient.SendAsync(apiRequest);
            }
            catch
            {
                return(RedirectToAction("UserDetails"));
            }

            if (!apiResponse.IsSuccessStatusCode)
            {
                return(RedirectToAction("UserDetails"));
            }

            PassCookiesToClient(apiResponse);


            // Edit Identity User
            apiRequest         = CreateRequestToService(HttpMethod.Put, "Accounts/Edit");
            apiRequest.Content = new ObjectContent <AccountEdit>(user, new JsonMediaTypeFormatter());

            try
            {
                apiResponse = await HttpClient.SendAsync(apiRequest);
            }
            catch
            {
                // TODO: Rollback User edit
                return(RedirectToAction("UserDetails"));
            }

            if (!apiResponse.IsSuccessStatusCode)
            {
                return(RedirectToAction("UserDetails"));
            }

            PassCookiesToClient(apiResponse);


            return(RedirectToAction("UserDetails"));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> Edit([FromBody] AccountEdit account)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model state invalid"));
            }

            try
            {
                var userStore   = new UserStore <IdentityUser>(new AccountDbContext());
                var userManager = new UserManager <IdentityUser>(userStore);
                var user        = userManager.Users.First(x => x.UserName == account.Username);
                if (user == null)
                {
                    throw new ArgumentException("account");
                }

                if (!userManager.CheckPassword(user, account.Password))
                {
                    return(Unauthorized());
                }

                if (userManager.HasPassword(user.Id))
                {
                    userManager.RemovePassword(user.Id);
                }

                var hashedPw = userManager.PasswordHasher.HashPassword(account.newPassword);

                await userStore.SetPasswordHashAsync(user, hashedPw);

                await userManager.UpdateAsync(user);

                user.UserName = account.newUsername ?? account.Username;
                user.Email    = account.newEmail;
                userStore.Context.SaveChanges();

                // Refresh
                Request.GetOwinContext().Authentication.SignOut(WebApiConfig.AuthenticationType);
                var authManager    = Request.GetOwinContext().Authentication;
                var claimsIdentity = userManager.CreateIdentity(user, WebApiConfig.AuthenticationType);
                authManager.SignIn(new AuthenticationProperties {
                    IsPersistent = true
                }, claimsIdentity);

                return(Ok());
            }
            catch
            {
                return(BadRequest("Invalid user"));
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(int id)
        {
            var svc    = CreateAccountService();
            var detail = svc.GetAccountById(id);
            var model  =
                new AccountEdit
            {
                AccountId    = detail.AccountId,
                AcctName     = detail.AcctName,
                AcctPassword = detail.AcctPassword
            };

            return(View(model));
        }
Exemplo n.º 5
0
        private void AccountEdit_EditValueChanged(object sender, EventArgs e)
        {
            if (AccountEdit.ContainsFocus)
            {
                var row = AccountEdit.GetSelectedDataRow() as user_acc;
                if (row != null && row.ExtDocType == -1)
                {
                    KagentComboBox.EditValue = row.KaId;
                    KagentComboBox.Enabled   = false;
                }
                else
                {
                    KagentComboBox.Enabled = true;
                }
            }

            GetOk();
        }
Exemplo n.º 6
0
        public IHttpActionResult Put(AccountEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Make sure the note exists.
            var acctService = new AccountService(Guid.Parse(User.Identity.GetUserId()));
            var temp        = acctService.GetAccountById(model.AccountId);

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

            // Attempt to update.
            return(Ok(acctService.UpdateAccount(model)));
        }
Exemplo n.º 7
0
        public bool UpdateAccount(AccountEdit model)
        {
            string key        = "sKzvYk#1Pn33!YN";
            string userInput  = model.AcctPassword;
            string ciphertext = Rijndael256.Rijndael.Encrypt(userInput, key, Rijndael256.KeySize.Aes256);

            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Accounts
                    .Single(e => e.AccountId == model.AccountId && e.OwnerId == _userId);

                entity.AcctName     = model.AcctName;
                entity.AcctPassword = ciphertext;
                entity.UpdatedUtc   = DateTimeOffset.Now;

                return(ctx.SaveChanges() == 1);
            }
        }
        public IActionResult Edit([FromBody] AccountEdit acc)
        {
            try
            {
                var     username = User.Identity.Name;
                Account edited   = Context.Account.Find(username);

                edited.Name   = acc.Name;
                edited.Status = acc.Status;

                Context.Account.Update(edited);
                Context.SaveChanges();

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Exemplo n.º 9
0
        // GET: Accounts/EditUser
        public async Task <ActionResult> EditUser()
        {
            UserAPI user = await WhoAmI();

            if (user == null)
            {
                TempData["Message"] = "Please log in.";
                return(RedirectToAction("Login", "Accounts"));
            }

            AccountEdit editUser = new AccountEdit();

            editUser.Username    = user.Username;
            editUser.newUsername = user.Username;
            editUser.Email       = user.Email;
            editUser.newEmail    = user.Email;
            editUser.Created     = user.Created;
            editUser.Modified    = user.Modified;
            editUser.Id          = user.Id;

            return(View(editUser));
        }
Exemplo n.º 10
0
        /**
         * Returns the edit operations that failed.
         */
        public AccountEdit EditAccount([FromBody] AccountEdit edits)
        {
            var errors = new AccountEdit();

            using (var transaction = _dbContext.Database.BeginTransaction()) {
                try {
                    foreach (var(email, editOperation) in edits.Edits)
                    {
                        if (!ExecuteAccountEdit(email, editOperation))
                        {
                            errors.Edits[email] = editOperation;
                        }
                    }
                    transaction.Commit();
                }catch (Exception e) {
                    _logger.LogError(e, "Error while editing account! All updates discarded.");
                    transaction.Rollback();
                    return(edits);
                }
            }
            return(errors);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Execute Account.Edit() method
        /// </summary>
        private static void AccountEdit(Account transportAccount, string accountNumber)
        {
            var accountEdit = new AccountEdit
            {
                AccountNumber = accountNumber,
                Business = transportAccount.Business,
                Individual = transportAccount.Individual
            };

            //Modify the First name
            transportAccount.Individual.NameFirst = transportAccount.Individual.NameFirst + ".";

            Helper.ShowResults("Account.Edit()",
                _session.Account.Edit(accountEdit)
                );
        }
Exemplo n.º 12
0
        /// <summary>
        /// Execute Account.Edit() method
        /// </summary>
        private static void AccountEditError(Account transportAccount)
        {
            var accountEdit = new AccountEdit
            {
                AccountNumber = "xxxxxxxxxxxx",
                Business = transportAccount.Business,
                Individual = transportAccount.Individual
            };

            Helper.ShowResults("Account.Edit() - cause exception",
                _session.Account.Edit(accountEdit)
                );
        }
Exemplo n.º 13
0
        private void InitAccountEdit(IAccount acct, IOrg org)
        {
            AccountEdit acctEdit = new AccountEdit();

            // null means adding a new account

            if (acct != null)
            {
                acctEdit.OrgID            = acct.OrgID;
                acctEdit.AccountID        = acct.AccountID;
                acctEdit.AccountName      = acct.AccountName;
                acctEdit.AccountNumber    = acct.AccountNumber;
                acctEdit.AccountTypeID    = acct.AccountTypeID;
                acctEdit.FundingSourceID  = acct.FundingSourceID;
                acctEdit.Managers         = AccountEditUtility.GetManagerEdits(acct.AccountID);
                acctEdit.ShortCode        = acct.ShortCode.Trim();
                acctEdit.SpecialTopicID   = acct.SpecialTopicID;
                acctEdit.TechnicalFieldID = acct.TechnicalFieldID;
                acctEdit.InvoiceNumber    = acct.InvoiceNumber;
                acctEdit.InvoiceLine1     = acct.InvoiceLine1;
                acctEdit.InvoiceLine2     = acct.InvoiceLine2;
                acctEdit.PoEndDate        = acct.PoEndDate;
                acctEdit.PoInitialFunds   = acct.PoInitialFunds;
                acctEdit.PoRemainingFunds = acct.PoRemainingFunds;

                acctEdit.Addresses = new Dictionary <string, AddressEdit>
                {
                    { "billing", AccountEditUtility.GetAddressEdit(acct.BillAddressID) },
                    { "shipping", AccountEditUtility.GetAddressEdit(acct.ShipAddressID) }
                };

                if (AccountChartFields.IsChartFieldOrg(org))
                {
                    var cf = ServiceProvider.Current.Data.Account.GetChartFields(acct);
                    acctEdit.ChartFields = new AccountChartFieldEdit()
                    {
                        Account    = cf.Account,
                        Fund       = cf.Fund,
                        Department = cf.Department,
                        Program    = cf.Program,
                        Class      = cf.Class,
                        Project    = cf.Project,
                        ShortCode  = cf.ShortCode
                    };
                }
            }
            else
            {
                acctEdit.OrgID     = org.OrgID;
                acctEdit.Managers  = new List <AccountManagerEdit>();
                acctEdit.Addresses = new Dictionary <string, AddressEdit>
                {
                    { "billing", AccountEditUtility.GetAddressEdit(org.DefBillAddressID) },
                    { "shipping", AccountEditUtility.GetAddressEdit(org.DefShipAddressID) }
                };
                acctEdit.AccountTypeID = 1;

                if (AccountChartFields.IsChartFieldOrg(org))
                {
                    acctEdit.ChartFields = new AccountChartFieldEdit();
                }
            }

            Session["AccountEdit"] = acctEdit;
        }