惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
P
Privacy International News Feed
T
Tenable Blog
T
Threat Research - Cisco Blogs
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
L
LINUX DO - 热门话题
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
月光博客
月光博客
美团技术团队
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
NISL@THU
NISL@THU
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
Intezer
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Project Zero
Project Zero
Latest news
Latest news
博客园_首页
C
Cisco Blogs
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
H
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AWS News Blog
AWS News Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
Vercel News
Vercel News
Know Your Adversary
Know Your Adversary
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG

博客园 - 害羞的狮子王

无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.5 Delete删除用户] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.3 Details用户详细信息] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.1 Index用户列表] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证-2.2身份验证开发] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证--2.1使用Azure AD需要了解几个概念] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证] 无责任Windows Azure SDK .NET开发入门篇一[Windows Azure开发前准备工作] 建立小型开发团队的工作协作:翻译工作 建立小型开发团队的工作协作:讨论区 建立小型开发团队的工作协作:BugList 建立小型开发团队的工作协作:任务日历 建立小型开发团队的工作协作:简单的文档管理 建立小型开发团队的工作协作:管理调查和投票 建立小型开发团队的工作协作:管理链接 建立小型开发团队的工作协作:总览效果图 感谢微软BPOS4China技术支持组 远程为服务器安装Windows 2008 Server
无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.4 Edit修改用户信息]
害羞的狮子王 · 2015-08-10 · via 博客园 - 害羞的狮子王

3.4 Edit修改用户信息

我们用FormCollection简化了表单提交,非常方便的进行用户信息修改。

[HttpPost, Authorize]
public async Task<ActionResult> Edit(User user, FormCollection values)
{
    try
    {
        ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
        IUser toUpdate = await client.Users.GetByObjectId(values[“ObjectId”]).ExecuteAsync();
        foreach (var value in values)
        {
            var sourceProp = user.GetType().GetProperty(value.ToString(), BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
            var destProp = toUpdate.GetType().GetProperty(value.ToString(), BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
            if (null != sourceProp && sourceProp.CanRead)
            {
                if (null != destProp && destProp.CanWrite)
                {
                    destProp.SetValue(toUpdate, sourceProp.GetValue(user, null), null);
                }
            }
        }
        await toUpdate.UpdateAsync();
        return RedirectToAction("Index");
    }
    catch (Exception)
    {
        return View();
    }
}

对应的View代码为

@model Microsoft.Azure.ActiveDirectory.GraphClient.User
@{
    ViewBag.Title = "UserEdit";
}

<h2>UserEdit</h2>

@using (Html.BeginForm("Edit", "AzureActiveDirectory", null, FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.ValidationSummary(true)


    <div class="form-group">
        @Html.Label("照片", new { @class = "col-sm-2 control-label" })
        <input type=file name="photofile" class="col-sm-10" />
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.UserPrincipalName,"用户名(全名)", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.DisplayFor(model => model.UserPrincipalName)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.DisplayName,"显示名称", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.DisplayName)
            @Html.ValidationMessageFor(model => model.DisplayName)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.AccountEnabled,"账号状态", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.AccountEnabled)
            @Html.ValidationMessageFor(model => model.AccountEnabled)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.GivenName,"名字", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.GivenName)
            @Html.ValidationMessageFor(model => model.GivenName)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Surname,"姓氏", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.Surname)
            @Html.ValidationMessageFor(model => model.Surname)
        </div>
    </div>


    <div class="form-group">
        @Html.LabelFor(model => model.JobTitle,"职务", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.JobTitle)
            @Html.ValidationMessageFor(model => model.JobTitle)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Department,"部门", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.Department)
            @Html.ValidationMessageFor(model => model.Department)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Mobile, new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.Mobile)
            @Html.ValidationMessageFor(model => model.Mobile)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.StreetAddress,"街道地址", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.StreetAddress)
            @Html.ValidationMessageFor(model => model.StreetAddress)
        </div>
    </div>


    <div class="form-group">
        @Html.LabelFor(model => model.City,"城市", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.State,"省/自治区/直辖市", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.State)
            @Html.ValidationMessageFor(model => model.State)
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Country,"国家或地区", new { @class = "col-sm-2 control-label" })
        <div class="col-sm-10">
            @Html.EditorFor(model => model.Country)
            @Html.ValidationMessageFor(model => model.Country)
        </div>
    </div>
    <p>
        <input type="submit" value="Edit" class="btn btn-primary" />
    </p>

}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

成功运行后的效果为

4

返回Index,你会观察到职务列有了信息

5