Example #1
0
        public ActionResult Edit(string id, ViewAccountModel model)
        {
            try
            {
                var guid    = Guid.Parse(id);
                var account = (from a in Warehouse.db.Account
                               where a.Account_ID == guid
                               select a).FirstOrDefault();
                if (account != null)
                {
                    account.Account_Name = model.UserName;
                    foreach (var accountRole in model.Roles)
                    {
                        if (accountRole.Is)
                        {
                            Warehouse.SetUserRole(accountRole.RoleType, guid, accountRole.Until);
                        }
                    }
                    Warehouse.db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Edit", new { model.Id }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Index(ViewAccountModel model)
        {
            if (!Roles.GetRolesForUser(WebSecurity.CurrentUserName).Contains("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }

            string [] roles = Roles.GetRolesForUser(model.UserName);

            // dont know how to make easier.
            if (model.AdminChecked)
            {
                if (!roles.Contains("Admin"))
                {
                    Roles.AddUserToRole(model.UserName, "Admin");
                }
            }
            else
            {
                if (roles.Contains("Admin"))
                {
                    Roles.RemoveUserFromRole(model.UserName, "Admin");
                }
            }
            if (model.EngineerChecked)
            {
                if (!roles.Contains("Engineer"))
                {
                    Roles.AddUserToRole(model.UserName, "Engineer");
                }
            }
            else
            {
                if (roles.Contains("Engineer"))
                {
                    Roles.RemoveUserFromRole(model.UserName, "Engineer");
                }
            }
            if (model.OperatorChecked)
            {
                if (!roles.Contains("Operator"))
                {
                    Roles.AddUserToRole(model.UserName, "Operator");
                }
            }
            else
            {
                if (roles.Contains("Operator"))
                {
                    Roles.RemoveUserFromRole(model.UserName, "Operator");
                }
            }
            return(View(model));
        }
Example #3
0
        public async Task <ActionResult> OpenAccount(ViewAccountModel account)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            string openedAccountNumber = _bankAccountService.CreateAccount(account.Type, _numberGenerator, account.OwnerFirstName,
                                                                           account.OwnerSecondName, account.OwnerEmail, account.Balance, account.Bonus);

            string subject = "Account is successfully opened!";
            string message = $"Your account number: {openedAccountNumber}";

            await SendMailAsync(account.OwnerEmail, subject, message);

            TempData["accountOpened"] = true;
            return(RedirectToAction("AccountIsOpened"));
        }
 public ActionResult Index(ViewAccountModel model, int AccountID)
 {
     if (!Roles.GetRolesForUser(WebSecurity.CurrentUserName).Contains("Admin"))
     {
         return(RedirectToAction("Index", "Home"));
     }
     using (var db = new LoginContexts())
     {
         SimpleMembershipProvider provider = new SimpleMembershipProvider();
         UserProfile Profile = db.UserProfiles.Find(AccountID);
         model.UserName = Profile.UserName;
         string[] AccountRoles = Roles.GetRolesForUser(Profile.UserName);
         model.AdminChecked    = AccountRoles.Contains("Admin");
         model.EngineerChecked = AccountRoles.Contains("Engineer");
         model.OperatorChecked = AccountRoles.Contains("Operator");
         return(View(model));
     }
 }