管理帐户mvc app c#

时间:2017-12-19 15:55:58

标签: c# asp.net asp.net-mvc-4 model-view-controller

我正在尝试将“管理”链接重定向到相关帐户。 我有一个BankAccsController可以很好地查看登录用户的详细信息,并查看数据库中保存的两个帐户,但我想要做的是能够单击帐户右侧的相应按钮并将其设置为带我了解该特定帐户的详细信息。我知道我必须创建一个新的方法来替换当前的两个'ViewCurrent和ViewSavings'并使用参数,但我不确定如何做到这一点,并且无法找到正确的单词将其输入Google。

ePic of my accounts page

控制器

//View all accounts of logged in user
    [Authorize]
    public ActionResult Index()
    {
        var userId = User.Identity.GetUserId();
        var bankAccs = db.BankAccs.Where(a => a.AccUserId == userId).ToList();
        return View(bankAccs.ToList());
    }

    ////View current account  of logged in user
    public ActionResult ViewCurrent()
    {

        var userId = User.Identity.GetUserId();
        ViewModels.CurrentAccVm bankVm = new ViewModels.CurrentAccVm();
        bankVm.BankAccList = db.BankAccs.Where(a => a.AccUserId == userId && a.AccTypeId == 1).ToList();
        bankVm.UserName = User.Identity.GetUserName();
        return View(bankVm);
    }

    ////View Savings account  of logged in user
    public ActionResult ViewSavings()
    {
        var userId = User.Identity.GetUserId();
        ViewModels.CurrentAccVm bankVm = new ViewModels.CurrentAccVm();
        bankVm.BankAccList = db.BankAccs.Where(a => a.AccUserId == userId && a.AccTypeId == 2).ToList();
        bankVm.UserName = User.Identity.GetUserName();
        return View(bankVm);
    }

查看

     @model IEnumerable<Atm11.Models.BankAcc>

    @{
        ViewBag.Title = "Index";
    }

    <h2>Index</h2>

    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table class="table">
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Balance)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.AccType.AccountType)
            </th>
            <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Balance)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.AccType.AccountType)
            </td>
            <td>
                @Html.ActionLink("Manage", "ViewAccounts", new { id = item.Id })

            </td>
        </tr>
    }

    </table>

1 个答案:

答案 0 :(得分:2)

你真是太近了!将以下方法添加到您的控制器。您的视图构造正确,因此不需要对该文件进行任何更改。

<强>控制器

extension UIImage {

    func merge(in viewSize: CGSize, with imageTuples: [(image: UIImage, viewSize: CGSize, transform: CGAffineTransform)]) -> UIImage? {
        UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)

        print("scale : \(UIScreen.main.scale)")
        print("size : \(size)")
        print("--------------------------------------")

        guard let context = UIGraphicsGetCurrentContext() else { return nil }

        // Scale the context geometry to match the size of the image view that displayed me, because that's what all the transforms are relative to.
        context.scaleBy(x: size.width / viewSize.width, y: size.height / viewSize.height)

        draw(in: CGRect(origin: .zero, size: viewSize), blendMode: .normal, alpha: 1)

        for imageTuple in imageTuples {
            let areaRect = CGRect(origin: .zero, size: imageTuple.viewSize)

            context.saveGState()
            context.concatenate(imageTuple.transform)

            context.setBlendMode(.color)
            UIColor.purple.withAlphaComponent(0.5).setFill()
            context.fill(areaRect)

            imageTuple.image.draw(in: areaRect, blendMode: .normal, alpha: 1)

            context.restoreGState()
        }

        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return image
    }
}

接下来,您需要创建一个ViewAccounts视图。