示例#1
0
        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"));
        }
示例#2
0
        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();
        }
示例#3
0
        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"));
            }
        }
示例#4
0
 public IActionResult New(Content content)
 {
     _db.Content.Add(content);
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }