Esempio n. 1
0
        public void Create(CreateUser model, IValidationErrors errors)
        {
            if (!model.Validate(errors))
            {
                return;
            }

            if (UnitOfWork.Users.Any(x => x.UserName == model.UserName))
            {
                errors.Add("UserName", "UserName is already taken");
                return;
            }

            var user = model.MapTo <User>();

            foreach (var userModule in user.UserModules)
            {
                userModule.UserId = user.Id;
            }

            var result = UserManager.Create(user, model.Password);

            if (!result.Succeeded)
            {
                errors.AddErrorsFromResult(result);
                return;
            }

            model.UserId = user.Id;
        }