コード例 #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            var user = new ApplicationUser {
                UserName = model.Email
            };
            IdentityResult result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                IdentityUserRole <string> userrole = new IdentityUserRole <string>();
                var role = _db.Roles.FirstOrDefault(r => r.Name == "user");
                userrole.RoleId = role.Id;
                userrole.UserId = user.Id;
                _db.UserRoles.Add(userrole);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
コード例 #2
0
        private Argument PerformEdit(string text, bool affirmative, int parentId, int id)
        {
            Argument argument = _db.Arguments.FirstOrDefault(a => a.ArgumentId == id);

            argument.Text = text ?? argument.Text;
            if (!argument.IsCitation)
            {
                argument.IsAffirmative = affirmative;
            }
            argument.ParentId         = parentId == 0 ? argument.ParentId : parentId;
            _db.Entry(argument).State = EntityState.Modified;
            _db.SaveChanges();
            return(argument);
        }