public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
public class UsersController : System.Web.Http.ApiController
{
[HttpPost]
public void Add(string id, int p1)
{
}
}
internal sealed class Configuration : DbMigrationsConfiguration<Models.ApplicationDbContext>
{
public Configuration()
{
...
ContextKey = "ApplicationDbContextKeyName";
}
var context = new ApplicationDbContext();
var roleStore = new RoleStore<IdentityRole>(context);
var roleMgr = new RoleManager<IdentityRole>(roleStore);
roleMgr.FindByName("Admin").Users - даёт список пользователей.
@using (Html.BeginForm())
{
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Сохранить" class="btn btn-primary" />
@Html.ActionLink("Отмена", "Index", null, new { @class="btn btn-default"})
</div>
</div>
</div>
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(AspNetRole model)
{
if (ModelState.IsValid)
{
db.Entry(model).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}