Пример #1
0
        public ActionResult Create(UserModel userModel)
        {
            if (userModel.Password.IsNullOrEmpty())
                ModelState.AddModelError("Password", "Please fill in a password.");

            if (!ModelState.IsValid)
                return View(userModel);

            var user = new User();

            user.Username = userModel.User.Username;

            if (!userModel.Password.IsNullOrEmpty())
                user.PasswordHashed = Hash.Make(userModel.Password);

            user.DateCreated = DateTime.Now;
            user.Role = userModel.User.Role;
            user.Email = userModel.User.Email;
            user.Website = FixWebsiteUrl(userModel.User.Website);
            user.TwitterUsername = FixTwitterUsername(userModel.User.TwitterUsername);
            _userService.Create(user);
            _userService.Save();

            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            var user = _userService.GetById(id);

            if (user == null)
                return View("NotFound", new NotFoundModel());

            var model = new UserModel(user);

            return View(model);
        }
Пример #3
0
        public ActionResult Edit(int id, UserModel userModel)
        {
            if (!ModelState.IsValid)
                return View(userModel);

            var user = _userService.GetById(id);

            user.Username = userModel.User.Username;

            if (!userModel.Password.IsNullOrEmpty())
                user.PasswordHashed = Hash.Make(userModel.Password);

            user.Role = userModel.User.Role;
            user.Email = userModel.User.Email;
            user.Website = FixWebsiteUrl(userModel.User.Website);
            user.TwitterUsername = FixTwitterUsername(userModel.User.TwitterUsername);

            _userService.Save();

            return RedirectToAction("Index");
        }