public async Task <OperationResult <SignUpDto> > SignUp(SignUpDto signUpDto)
        {
            OperationResult <SignUpDto> operation = new OperationResult <SignUpDto>();

            try
            {
                using (var transaction = Context.Database.BeginTransaction())
                {
                    try
                    {
                        IdenServUser SetUser = new IdenServUser()
                        {
                            UserName           = signUpDto.UserName,
                            Email              = signUpDto.UserName,
                            NormalizedUserName = signUpDto.FirstName + " " + signUpDto.LastName
                        };

                        var result = await UserManager.CreateAsync(SetUser, signUpDto.Password);


                        if (result == IdentityResult.Success)
                        {
                            operation.Result = signUpDto;
                            operation.OperationResultType    = OperationResultTypes.Success;
                            operation.OperationResultMessage = "Success CreateAsync execution :" + nameof(SignUp);
                            transaction.Commit();
                            return(operation);
                        }

                        operation.OperationResultType    = OperationResultTypes.Failed;
                        operation.OperationResultMessage = "Faild DuplicateUserName CreateAsync execution :" + nameof(SignUp);
                        transaction.Rollback();

                        return(operation);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        operation.OperationResultType    = OperationResultTypes.Exeption;
                        operation.OperationResultMessage = "Exeption execution :" + nameof(SignUp);
                        operation.Exception = ex;

                        return(operation);
                    }
                }
            }
            catch (Exception ex)
            {
                operation.OperationResultType    = OperationResultTypes.Exeption;
                operation.OperationResultMessage = "Exeption execution :" + nameof(SignUp);
                operation.Exception = ex;
            }
            return(operation);
        }
Esempio n. 2
0
        public static async Task InitializeAsync(IServiceProvider serviceProvider)
        {
            var userManager = (UserManager <IdenServUser>)serviceProvider.GetService(typeof(UserManager <IdenServUser>));
            var context     = (IdenServeContext)serviceProvider.GetService(typeof(IdenServeContext));

            var admin = await userManager.FindByNameAsync("GeoMed");

            if (admin == null)
            {
                admin = new IdenServUser()
                {
                    UserName  = "******",
                    Email     = "*****@*****.**",
                    FirstName = "Geo",
                    LastName  = "Med"
                };

                await userManager.CreateAsync(admin, "123456");

                await context.SaveChangesAsync();
            }
        }