public async Task <IActionResult> New(Comment comment) { comment.PostDate = DateTime.Now; var userId = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; comment.User = await _userManager.FindByIdAsync(userId); string thisUser = _userManager.GetUserId(User); ViewBag.User = _db.Users.Where(u => u.Id == thisUser).FirstOrDefault(); _db.Comments.Add(comment); _db.SaveChanges(); return(RedirectToAction("Index")); }
public static void Initialize(AstroPodDbContext context) { if (context.Roles.Any()) { return; } var roles = new IdentityRole[] { new IdentityRole() { Name = "Admin" } }; var content = new Content[] { }; foreach (var r in roles) { context.Roles.Add(r); } foreach (var r in roles) { context.Roles.Add(r); } context.SaveChanges(); }
public async Task <IActionResult> Register(RegisterViewModel model) { AppUser user = new AppUser { UserName = model.UserName, Email = model.Email, BirthDate = model.BirthDate }; user.Roles.Add(new IdentityUserRole <string> { RoleId = Request.Form["role"] }); IdentityResult result = await _userManager.CreateAsync(user, model.Password); user.SetData(); user.SetZod(); user.SetMoonData(); user.SetMoonZod(); user.SetMercData(); user.SetMercZod(); user.SetVenusData(); user.SetVenusZod(); user.SetMarsData(); user.SetMarsZod(); user.SetJupiterData(); user.SetJupiterZod(); user.SetSaturnData(); user.SetSaturnZod(); user.SetUranusData(); user.SetUranusZod(); user.SetNeptuneData(); user.SetNeptuneZod(); _db.SaveChanges(); if (result.Succeeded) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Register")); } }
public IActionResult New(Content content) { _db.Content.Add(content); _db.SaveChanges(); return(RedirectToAction("Index")); }