本文整理汇总了C#中ApplicationManager.FindByNameAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationManager.FindByNameAsync方法的具体用法?C# ApplicationManager.FindByNameAsync怎么用?C# ApplicationManager.FindByNameAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationManager
的用法示例。
在下文中一共展示了ApplicationManager.FindByNameAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
// GET: Default
public async Task<ActionResult> Index()
{
if (User.Identity.IsAuthenticated)
{
using (ApplicationDBContext db = new ApplicationDBContext())
{
var UM = new ApplicationManager(new UserStore<ApplicationUser>(db));
var user = await UM.FindByNameAsync(User.Identity.Name);
ViewBag.Age = user?.Year;
ViewBag.Sex = user?.Sex;
}
}
return View();
}
示例2: Details
public async Task<ActionResult> Details([Bind(Include = "Text")]Reply reply, int? id)
{
var url = Request.UrlReferrer.AbsolutePath;
reply.Date = DateTime.Now;
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Message message = db.Messages.Find(id);
if (message == null)
{
return HttpNotFound();
}
if (ModelState.IsValid)
{
reply.Message = message;
var UM = new ApplicationManager(new UserStore<ApplicationUser>(db));
if (User.Identity.IsAuthenticated) reply.Avtor = await UM.FindByNameAsync(User.Identity.Name);
db.Replys.Add(reply);
db.SaveChanges();
}
return View(reply.Message);
}
示例3: Create
public async Task<ActionResult> Create([Bind(Include = "Id,Title,Text,PubDate")] Message message, HttpPostedFileBase Image)
{
Session["Create"] = "Yes";
if (ModelState.IsValid)
{
using (var transaction = new System.Transactions.TransactionScope())
{
if (Image != null)
{
File file = new File();
file.Ex = System.IO.Path.GetExtension(Image.FileName);
db.Files.Add(file);
message.File = file;
db.SaveChanges();
Image.SaveAs(Server.MapPath("~/App_FrontEnd/UploadFiles/" + file.FileName));
}
transaction.Complete();
}
var UM = new ApplicationManager(new UserStore<ApplicationUser>(db));
if (User.Identity.IsAuthenticated) message.Avtor = await UM.FindByNameAsync(User.Identity.Name);
db.Messages.Add(message);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(message);
}