public async Task <IActionResult> OnPostAsync()
        {
            Alert alert = new Alert(AlertType.success);

            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (_client.TypePerson == "J")
            {
                _client.Name = _name;
            }
            await _clientController.Create(_client);

            alert.Text = "Cliente criado com sucesso!";
            alert.ShowAlert(PageContext);

            return(Page());
        }
Пример #2
0
        public User Register(RegistrationRequest registrationRequest)
        {
            User user = null;
            var  val  = ValidationHelper.ValidateEntity <RegistrationRequest>(registrationRequest);

            Util.SetAnonymousCredentials();

            if (!val.HasError)
            {
                //Will check of the email  is already registered
                var exp = PredicateBuilder.Create <User>(d => d.Email == registrationRequest.Email &&
                                                         d.DeletedDate == null &&
                                                         d.DeletedUser == null);

                if (!Repository.Any <User>(exp))
                {
                    Client client = new Client();
                    client.Name     = registrationRequest.Client;
                    client.UniqueId = Guid.NewGuid().ToString();
                    client.Name     = registrationRequest.Client;

                    client = clientController.Create(client);

                    user           = new User();
                    user.UserName  = registrationRequest.Email;
                    user.FirstName = registrationRequest.FirstName;
                    user.LastName  = registrationRequest.LastName;
                    user.Salt      = Guid.NewGuid().ToString().Substring(0, 5);
                    user.Password  = HashProvider.CreateHash(user.Salt + registrationRequest.Password);
                    user.PhotoPath = "../img/profile_small.jpg";
                    user.Email     = registrationRequest.Email;
                    user.Client    = client;
                    user.UniqueId  = Guid.NewGuid().ToString();
                    user.IsActive  = true;

                    //Make the user an administrator
                    Role adminRole = Repository.Get <Role>(1);
                    user.Roles.Add(adminRole);

                    user = Repository.Save <User>(user);

                    if (user != null)
                    {
                        Log.Info(String.Format("USER CREATED : ID:{0}", user.Id));
                        Debug.WriteLine(String.Format("New user created {0}", user.Id));

                        RegistrationCompletedMessage registrationMessage = new RegistrationCompletedMessage(this, user);
                        MessageHub.Publish <RegistrationCompletedMessage>(registrationMessage);

                        Util.SetCredentials(user);

                        //Sent User Email Verification
                        CreateEmailVerificationRequest(user);
                    }
                }
                else
                {
                    throw new Exception("User with the same email address already exist");
                }
            }
            else
            {
                throw new ValidationException("Error while validating registration request", val.Errors);
            }

            return(user);
        }