예제 #1
0
        public ActionResult RemoveConfirmed(int id)
        {
            TradePlace tradePlace = db.TradePlaces.Find(id);

            if (tradePlace == null)
            {
                return(HttpNotFound());
            }
            db.TradePlaces.Remove(tradePlace);
            db.SaveChangesAsync();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ConfirmedPassword != model.Password)
                {
                    ModelState.AddModelError("", "Passwords don`t match");
                    return(View(model));
                }
                User user = null;
                using (TradePlaceContext db = new TradePlaceContext())
                {
                    user = db.Users.FirstOrDefault(u => u.UserName == model.Login);
                }
                if (user == null)
                {
                    using (TradePlaceContext db = new TradePlaceContext())
                    {
                        var hashedPassword = BCrypt.Net.BCrypt.HashPassword(model.Password, WorkFactor);
                        Roles.AddUserToRole(model.Login, "User");

                        db.Users.Add(
                            new User {
                            UserName       = model.Login, PasswordHash = hashedPassword, EmailConfirmed = false,
                            LockoutEnabled = false, AccessFailedCount = 0
                        });
                        await db.SaveChangesAsync();

                        user = db.Users.Where(u => u.UserName == model.Login).FirstOrDefault();
                    }
                    if (user != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Login, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "User with this Login already exist");
                }
            }

            return(View(model));
        }