Exemple #1
0
        public ActionResult AddUserInline(UserModel model)
        {
            if (ModelState.IsValid)
            {
                var subscription = Context.Database.Subscriptions.GetById(WebSecurity.CurrentUserSubscriptionId);
                var email = string.Format("{0}@{1}", model.UserName, subscription.EmailDomain);

                User existingUser;
                if (Context.Users.TryGetByEmail(email, out existingUser))
                {
                    ModelState.AddModelError("username", "There is already and user with the name you entered, please choose a different one.");
                    return PartialView("_AddUserInline", model);
                }

                var user = new User
                {
                    SubscriptionId = subscription.Id,
                    Name = model.Name,
                    Email = email,
                    Password = SecurityManager.Hash("123") //TODO: replace this for an autogenerated password.
                };

                Context.Database.Users.Add(user);

                //TODO: send activation email.
            }

            return PartialView("_AddUserInline", model);
        }
        public ActionResult AccountMenu()
        {
            User user;
            if (!WebSecurity.TryGetCurrentUser(out user))
                throw new InvalidOperationException("user is not authenticated!");

            var model = new UserModel
            {
                Id = user.Id,
                Email = user.Email,
                Name = user.Name,
            };

            return PartialView("_AccountMenu", model);
        }
        public ActionResult AddUserInline(UserModel model)
        {
            if (ModelState.IsValid)
            {
                Context.Users.Add(new User
                {
                    Name = model.Name,
                    Email = model.Email,
                    Password = SecurityManager.Hash("123") //TODO: replace this for an autogenerated password.
                });

                Context.SaveChanges();

                //TODO: send activation email.
            }

            return PartialView("_AddUserInline", model);
        }
Exemple #4
0
        public ActionResult EditUser(UserModel model)
        {
            if (ModelState.IsValid)
            {
                User user;
                if (!Context.Users.TryGetById(model.Id, out user))
                    throw new InvalidOperationException(string.Format("user with id {0} was not found", model.Id));

                user.Name = model.Name;
                Context.SaveChanges();
            }

            return JsonView(ModelState.IsValid, "_EditUser", model);
        }
Exemple #5
0
        public ActionResult EditUser(long userId)
        {
            User user;
            if (!Context.Users.TryGetById(userId, out user))
                throw new InvalidOperationException(string.Format("user with id {0} was not found", userId));

            var model = new UserModel
            {
                Id = user.Id,
                Name = user.Name
            };

            return PartialView("_EditUser", model);
        }