Пример #1
0
        public async Task <MxReturnCode <bool> > DeleteUrdAsync(string name)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"AdminRepository.DeleteUrdAsync(name={name ?? "[null]"})");

            if (string.IsNullOrWhiteSpace(name))
            {
                rc.SetError(1010501, MxError.Source.Param, "name is null");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "DELETE FROM GdprUrd WHERE Name = @Name";
                        var res = await db.ExecuteAsync(sql, new { Name = name });

                        if (res != 1)
                        {
                            rc.SetError(1010502, MxError.Source.Data, $"record not deleted: name={name ?? "[null]"}");
                        }
                        else
                        {
                            //also delete corresponding WXR - is there a trigger?
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1010503, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #2
0
        public async Task <MxReturnCode <bool> > IsExistUrdAsync(string name)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"AdminRepository.IsExistUrdAsync(name={name ?? "[null]"})");

            if (String.IsNullOrWhiteSpace(name))
            {
                rc.SetError(1010101, MxError.Source.Param, "name is null or empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "SELECT * FROM GdprUrd WHERE Name = @Name";
                        var res = await db.QuerySingleOrDefaultAsync <GdprUrd>(sql, new { Name = name });

                        if ((res == null) || (res.Name != name))
                        {
                            rc.SetResult(false);
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1010102, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #3
0
        public async Task <MxReturnCode <bool> > UpdateUrdAsync(string roleName, int roleCode, UrdStatus roleStatus, string purpose, string description)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"AdminRepository.UpdateUrdAsync({roleName ?? "[null]"})");

            if (String.IsNullOrWhiteSpace(roleName) || String.IsNullOrWhiteSpace(purpose) || String.IsNullOrWhiteSpace(description) || (GdprUrd.IsValidRoleCode(roleCode) == false))
            {
                rc.SetError(1010401, MxError.Source.Param, "roleName, purpose or description is null or empty, or rolecode is invalid");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "UPDATE GdprUrd SET RoleCode = @RoleCode, Status = @Status, Purpose = @Purpose, Description = @Description WHERE Name = @Name;";
                        var res = await db.ExecuteAsync(sql, new { RoleCode = roleCode, Status = (int)roleStatus, Purpose = purpose, Description = description, Name = roleName });

                        if (res != 1)
                        {
                            rc.SetError(1010402, MxError.Source.Data, $"record not updated: Name={roleName}");
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1010403, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }

            return(rc);
        }
Пример #4
0
        public async Task <MxReturnCode <GdprRpd> > GetRpdAsync(string email)
        {
            MxReturnCode <GdprRpd> rc = new MxReturnCode <GdprRpd>("SystemRepo.GetRpdAsync()");

            if (String.IsNullOrWhiteSpace(email))
            {
                rc.SetError(1040301, MxError.Source.Param, "invalid email");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "SELECT * FROM GdprRpd WHERE Email = @Email";
                        var res = await db.QuerySingleOrDefaultAsync <GdprRpd>(sql, new { Email = email });

                        rc.SetResult(res);
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1040302, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #5
0
        public MxReturnCode <bool> CheckConnection()
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("CheckConnection()", false);

            if (db == null)
            {
                rc.SetError(1010101, MxError.Source.AppSetting, String.Format("invalid connection {0}", DbConnectionForDisplay ?? "null", MxMsgs.MxErrDbConnNotSet));
            }
            else
            {
                try
                {
                    if (db.State != ConnectionState.Open)
                    {
                        db.Open();
                    }
                    if (db.State != ConnectionState.Open)
                    {
                        rc.SetError(1010102, MxError.Source.Sys, String.Format("cannot open database connection {0}", DbConnectionForDisplay ?? "[null]"), MxMsgs.MxErrDbConnClosed);
                    }
                    else
                    {
                        rc.SetResult(true);
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1010103, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbConnException, true);
                }
            }
            return(rc);
        }
Пример #6
0
        public async Task <MxReturnCode <bool> > UpdateRoleAsync(GdprUrd role, string name, int rolecode, string purpose, string description, GdprUrd.StatusVal status)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.UpdateRoleAsync()", false);

            if ((role == null) || (RepositoryBase.IsGuidSet(role.Id) == false) || (String.IsNullOrWhiteSpace(name)) || (GdprUrd.IsValidRoleCode(rolecode) == false))
            {
                rc.SetError(1020401, MxError.Source.Param, "role is null, role.Id is not set, name is null or emptpy, or rolecode is invalid");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "UPDATE GdprUrd SET Name = @Name, RoleCode = @RoleCode, Status = @Status, Purpose = @Purpose, Description = @Description WHERE Id = @Id;";
                        var res = await db.ExecuteAsync(sql, new { Name = name, RoleCode = rolecode, Status = (int)status, Purpose = purpose, Description = description, Id = role.Id });

                        if (res != 1)
                        {
                            rc.SetError(1020402, MxError.Source.Data, String.Format("record not updated {0}", role.ToString()));
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020403, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #7
0
        public async Task <IActionResult> OnGetAsync(string msgJson)
        {
            MxReturnCode <IActionResult> rc = new MxReturnCode <IActionResult>("Index.OnGetAsync()", Page());

            try
            {
                using (IAdminRepository repository = new AdminRepository(_conn))
                {
                    var resCnt = await repository.GetRoleCountAsync();

                    rc += resCnt;
                    if (rc.IsSuccess())
                    {
                        URDCount = String.Format("URD Count = {0}", resCnt.GetResult());
                        SetPageStatusMsg("Database access ok", ExistingMsg.Keep);
                        rc.SetResult(Page());
                    }
                }
            }
            catch (Exception e)
            {
                rc.SetError(3130101, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
            }
            if (rc.IsError())
            {
                _logger.LogError(rc.GetErrorTechMsg());
                SetPageStatusMsg(rc.GetErrorUserMsgHtml(Startup.WebAppName, WebErrorHandling.GetMxRcReportToEmailBody()), ExistingMsg.Overwrite);
            }
            return(rc.GetResult());
        }
Пример #8
0
        private async Task <MxReturnCode <bool> > DeseedStdTermsConditions(GdprSeedRepo gdprSeedRepo)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"MxIdentityDb.DeseedStdTermsCondition");

            if (gdprSeedRepo == null)
            {
                rc.SetError(3060301, MxError.Source.Param, "gdprSeedRepo is null");
            }
            else
            {
                var resGetExisting = await gdprSeedRepo.GetWstAsync(_config["WST:Standard"]);

                rc += resGetExisting;
                if (rc.IsSuccess())
                {
                    if (resGetExisting.GetResult() == null)
                    {
                        rc.SetResult(true);
                    }
                    else
                    {
                        //delete resGetExisting.GetResult()
                        rc.SetResult(true);
                    }
                }
            }
            return(rc);
        }
Пример #9
0
        public async Task <MxReturnCode <bool> > DeleteRoleAsync(GdprUrd role)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.DeleteRoleAsync()", false);

            if (role == null)
            {
                rc.SetError(1020301, MxError.Source.Param, "role is null");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "DELETE FROM GdprUrd WHERE Id = @Id";
                        var res = await db.ExecuteAsync(sql, new { Id = role.Id });

                        if (res != 1)
                        {
                            rc.SetError(1020302, MxError.Source.Data, String.Format("record not deleted {0}", role.ToString()));
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020303, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #10
0
        public async Task <MxReturnCode <bool> > CreateRpdAsync(string email, string fullName, RpdChildFlag childFlag, string roleName, Guid identityUserId)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("SystemRepo.CreateRpdAsync()");

            if (String.IsNullOrWhiteSpace(email))
            {
                rc.SetError(1040201, MxError.Source.Param, "invalid email");
            }
            else
            {
                try
                {
                    //Pass AspNetUsers.ID
                    //Pass Role name
                    //Get URD ID
                    //Get all WXR for URDID
                    //Find lastest WST in WXR list
                    //create RPD
                    //Create UTA for WST and RPD
                }
                catch (Exception e)
                {
                    rc.SetError(1040202, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #11
0
        public async static Task <bool> IsExistsUser(ISysRepository repo, UserManager <IdentityUser> userManager, string email)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("IdentityDb.CreateUser()", false);

            if ((repo == null) || (userManager == null) || (email == null))
            {
                rc.SetError(3160201, MxError.Source.Param, "repo, userManager or email is null", MxMsgs.MxErrUnexpected);
            }
            else
            {
                try
                {
                    //check identity
                    var result = await repo.GetUserAsync(email);

                    rc += result;
                    if (result.IsSuccess())
                    {
                        rc.SetResult(true);
                    }
                    else
                    {
                        rc.SetResult(false);
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(3160202, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
                }
            }
            return(rc.GetResult());
        }
Пример #12
0
        public async Task <MxReturnCode <bool> > DeleteRpdAsync(string email)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"AdminRepository.DeleteRpdAsync(email={email ?? "[null]"})");

            if (string.IsNullOrWhiteSpace(email))
            {
                rc.SetError(1040401, MxError.Source.Param, "email is null or empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "DELETE FROM GdprRpd WHERE Email = @Email";
                        var res = await db.ExecuteAsync(sql, new { Email = email });

                        if (res != 1)
                        {
                            rc.SetError(1040402, MxError.Source.Data, $"record not deleted: email={email ?? "[null]"}");
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1040403, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #13
0
        public async Task <MxReturnCode <bool> > IsExistRpdAsync(string email)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"SystemRepo.IsExistRpdAsync(email={email ?? "[null]"})");

            if (String.IsNullOrWhiteSpace(email))
            {
                rc.SetError(1040101, MxError.Source.Param, "email is null or empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "SELECT * FROM GdprRpd WHERE Email = @Email";
                        var res = await db.QuerySingleOrDefaultAsync <GdprRpd>(sql, new { Email = email });

                        if ((res == null) || (res.Email != email))
                        {
                            rc.SetResult(false);
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1040102, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #14
0
        static async Task <int> Main(string[] args)
        {
            MxReturnCode <int> rc = new MxReturnCode <int>($"{Program.WebAppName} v{Program.WebAppVersion}", 1);

            rc.Init(Assembly.GetExecutingAssembly(), "*****@*****.**", null, null, null, MxMsgs.SupportedCultures);

            Console.WriteLine(rc.GetInvokeDetails());

            var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("local.settings.json")
                         .Build();
            var conn = config?["ConnectionStrings:DefaultConnection"];  //03-12-18

            if (conn == null)
            {
                rc.SetError(2010101, MxError.Source.AppSetting, "config not built or ConnectionStrings:DefaultConnection not found");
            }
            else
            {
                using (IAdminRepo repo = new AdminRepo(conn))
                {
                    rc += await repo.GetUrdCountAsync();
                }
                if (rc.IsSuccess(true))
                {
                    Console.WriteLine($"Roles found = {rc.GetResult()}");
                    rc.SetResult(0);
                }
            }
            Console.WriteLine(rc.IsError(true) ? rc.GetErrorUserMsg() : $"Hello World!");
            Console.WriteLine(rc.IsError(true) ? rc.GetErrorTechMsg(): "no error");

            return(rc.GetResult());
        }
Пример #15
0
        public async Task <MxReturnCode <bool> > IsExistWstAsync(string title)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("ControllerRepository.IsExistWstAsync()");

            if (String.IsNullOrWhiteSpace(title))
            {
                rc.SetError(1020101, MxError.Source.Param, "title is null or empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "SELECT * FROM GdprWst WHERE Title = @Title";
                        var res = await db.QuerySingleOrDefaultAsync <GdprWst>(sql, new { Title = title });

                        rc.SetResult((res != null));
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020102, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #16
0
        public async static Task <bool> IsExistsRole(IAdminRepository repo, RoleManager <IdentityRole> roleManager, string gdprRolename)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("IdentityDb.IsExistsRole()", false);

            if ((repo == null) || (roleManager == null) || (gdprRolename == null))
            {
                rc.SetError(3160401, MxError.Source.Param, "repo, roleManager or rolename is null", MxMsgs.MxErrUnexpected);
            }
            else
            {
                try
                {
                    var identityRolename = AdminRepository.GetIdentityRolename(gdprRolename);
                    //check identity
                    var result = await repo.GetRoleAsync(gdprRolename);

                    rc += result;
                    if (result.IsSuccess())
                    {
                        rc.SetResult(true);
                    }
                    else
                    {
                        rc.SetResult(false);
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(3160402, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
                }
            }
            return(rc.GetResult());
        }
Пример #17
0
        public async Task <MxReturnCode <GdprUrd> > GetRoleAsync(string rolename)
        {
            MxReturnCode <GdprUrd> rc = new MxReturnCode <GdprUrd>("AdminRepository.GetRoleAsync(rolename)", null);

            if (String.IsNullOrWhiteSpace(rolename))
            {
                rc.SetError(1020501, MxError.Source.Param, "rolename is null or empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sql = "SELECT * FROM GdprUrd WHERE Name = @Name";
                        var res = await db.QuerySingleOrDefaultAsync <GdprUrd>(sql, new { Name = rolename });

                        rc.SetResult(res);
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020502, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Пример #18
0
        public async Task <MxReturnCode <int> > ResetAsync()
        {
            MxReturnCode <int> rc = new MxReturnCode <int>("MxIdentitySeedDb.ResetAsync()");

            try
            {
                using (var gdprSeedRepo = new GdprSeedRepo(_config?.GetConnectionString("DefaultConnection"))) //could also be GdprSeedRepoDummy
                {
                    var resWst = await DeseedStdTermsConditions(gdprSeedRepo);

                    rc += resWst;
                    if (rc.IsSuccess())
                    {
                        var wst = resWst.GetResult();

                        //var resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdAdmin, wst);
                        //rc += resRole;
                        //if (rc.IsSuccess())
                        //{
                        //    resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdController, wst);
                        //    rc += resRole;
                        //    if (rc.IsSuccess())
                        //    {
                        //        resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdStandard, wst);
                        //        rc += resRole;
                        //        if (rc.IsSuccess())
                        //        {
                        //            resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdSystem, wst);
                        //            rc += resRole;
                        //            if (rc.IsSuccess())
                        //            {
                        //                resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdGuest, wst);
                        //                rc += resRole;
                        //                if (rc.IsSuccess())
                        //                {
                        //                    resRole = await SeedStdUrdRole(gdprSeedRepo, AdminRepo.GdprUrdGhost, wst);
                        //                    rc += resRole;
                        //                    if (rc.IsSuccess())
                        //                    {

                        //                        //create GoldUser - [email protected]

                        //                        rc.SetResult(0);
                        //                    }
                        //                }
                        //            }
                        //        }
                        //    }
                        //}
                        rc.SetResult(0);
                    }
                }
            }
            catch (Exception e)
            {
                rc.SetError(3060201, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnexpected);
            }
            return(rc);
        }
Пример #19
0
        public async Task <MxReturnCode <bool> > CreateWstAsync(string title, string description, string url)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepo.CreateWstAsync()");

            rc += await _controllerRepo.CreateWstAsync(title, description, url);

            return(rc);
        }
Пример #20
0
        public async Task <MxReturnCode <GdprWst> > GetWstAsync(string title)
        {
            MxReturnCode <GdprWst> rc = new MxReturnCode <GdprWst> ("GdprSeedRepo.GetWstAsync()");

            rc += await _controllerRepo.GetWstAsync(title);

            return(rc);
        }
Пример #21
0
        public async Task <MxReturnCode <bool> > CreateStdUrdAsync(UrdCodeStd roleCode)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepoDummy.CreateUrdAsync()");

            rc.SetResult(true);

            return(rc);
        }
Пример #22
0
        public async Task <MxReturnCode <bool> > CreateWstAsync(string title, string description, string url)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepoDummy.CreateWstAsync()");

            rc.SetResult(true);

            return(rc);
        }
Пример #23
0
        public async Task <MxReturnCode <GdprWst> > GetWstAsync(string title)
        {
            MxReturnCode <GdprWst> rc = new MxReturnCode <GdprWst>("GdprSeedRepoDummy.GetWstAsync()");

            rc.SetResult(null);

            return(rc);
        }
Пример #24
0
        public async Task <MxReturnCode <bool> > DeleteStdUrdAsync(string urdName)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepoDummy.DeleteStdUrdAsync()");

            rc.SetResult(true);

            return(rc);
        }
Пример #25
0
        public async Task <MxReturnCode <bool> > CreateStdUrdAsync(string urdName, Guid wstId)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepoDummy.CreateStdUrdAsync()");

            rc.SetResult(true);

            return(rc);
        }
Пример #26
0
#pragma warning disable 1998
        public async Task <MxReturnCode <bool> > IsExistStdUrdAsync(string name)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepoDummy.IsExistUrdAsync()");

            rc.SetResult(true);

            return(rc);
        }
Пример #27
0
        private async Task <MxReturnCode <Guid> > SeedStdTermsConditions(GdprSeedRepo gdprSeedRepo)
        {
            MxReturnCode <Guid> rc = new MxReturnCode <Guid>("MxIdentityDb.CreateStdTermsConditions()");

            if (gdprSeedRepo == null)
            {
                rc.SetError(3060301, MxError.Source.Param, "gdprSeedRepo is null");
            }
            else
            {
                var resGetExisting = await gdprSeedRepo.GetWstAsync(_config["WST:Standard"]);

                rc += resGetExisting;
                if (rc.IsSuccess())
                {
                    if (resGetExisting.GetResult() != null)
                    {
                        rc.SetResult(resGetExisting.GetResult().Id);
                    }
                    else
                    {
                        var resCreate = await gdprSeedRepo.CreateWstAsync(_config["WST:Standard"], "descr", "url");

                        rc += resCreate;
                        if (rc.IsSuccess())
                        {
                            var resGetNew = await gdprSeedRepo.GetWstAsync(_config["WST:Standard"]);

                            rc += resGetNew;
                            if (rc.IsSuccess())
                            {
                                if (resGetExisting.GetResult() == null)
                                {
                                    rc.SetError(3060302, MxError.Source.Data, @"wst cannot be created",
                                                MxMsgs.MxErrUnexpected);
                                }
                                else
                                {
                                    var wst = resGetExisting.GetResult().Id;
                                    if (wst == Guid.Empty)
                                    {
                                        rc.SetError(3060303, MxError.Source.Sys,
                                                    @"wst Default not found and cannot be created", MxMsgs.MxErrUnexpected);
                                    }
                                    else
                                    {
                                        rc.SetResult(wst);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(rc);
        }
Пример #28
0
        private async Task <MxReturnCode <bool> > DeseedStdUrdRole(GdprSeedRepo gdprSeedRepo, string urdName, Guid wstId)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"MxIdentityDb.DeseedStdUrdRole(name={urdName ?? "[null]"})");

            if ((gdprSeedRepo == null) || (string.IsNullOrWhiteSpace(urdName)) || (gdprSeedRepo.GetStdGdprUrdCode(urdName) == UrdCodeStd.Undefined))
            {
                rc.SetError(3060401, MxError.Source.Param, $"gdprSeedRepo is null or urdName={urdName ?? "[null]"} is invalid");
            }
            else
            {
                var resUrdExists = await gdprSeedRepo.IsExistStdUrdAsync(urdName);

                rc += resUrdExists;
                if (rc.IsSuccess())
                {
                    if (resUrdExists.GetResult() == false)
                    {
                        var resCreate = await gdprSeedRepo.CreateStdUrdAsync(urdName, wstId);

                        rc += resCreate;
                    }
                    if (rc.IsSuccess())
                    {
                        var identityRoleName = gdprSeedRepo.XlatUrdNameToIdentityRoleName(urdName);
                        if (await _roleManager.FindByNameAsync(identityRoleName) != null)
                        {
                            rc.SetResult(true);
                        }
                        else
                        {
                            var idres = await _roleManager.CreateAsync(new IdentityRole()
                            {
                                Name = identityRoleName
                            });

                            if (idres.Succeeded)
                            {
                                rc.SetError(3060402, MxError.Source.Sys, $"unable to create Identity Role {identityRoleName ?? "[null]"}");
                            }
                            else
                            {
                                rc.SetResult(true);
                            }
                        }
                    }
                    if (rc.IsError(true))
                    {
                        await gdprSeedRepo.DeleteStdUrdAsync(urdName);
                    }
                }
            }
            return(rc);
        }
Пример #29
0
        public async static Task <MxReturnCode <bool> > CreateRole(IAdminRepository repo, RoleManager <IdentityRole> roleManager, Guid wst, string gdprRoleName)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("IdentityDb.CreateRole()");

            var identityRoleName = AdminRepository.GetIdentityRolename(gdprRoleName);

            if ((repo == null) || (roleManager == null) || (gdprRoleName == null) || (identityRoleName == null))
            {
                rc.SetError(3160301, MxError.Source.Param, "repo, roleManager or gdprRoleName is null", MxMsgs.MxErrUnexpected);
            }
            else
            {
                try
                {
                    if (await roleManager.RoleExistsAsync(identityRoleName) == false)
                    {
                        IdentityResult result = await roleManager.CreateAsync(new IdentityRole { Name = identityRoleName });

                        if (result.Succeeded == false)
                        {
                            rc.SetError(3160302, MxError.Source.Sys, WebErrorHandling.GetIdentityErrors(result, $"cannot create role {identityRoleName}"));
                        }
                    }
                    if (rc.GetErrorCode() == MxErrorLog.UnknownError)
                    {
                        //if gdprname exists - setresult

                        //create GDPR records; WST + URD and WXR record for each role 1) Admin 2) Controller  3) Standard 4) Guest 5) System (Guest) 6) Ghost (Guest)

                        //var resCnt = await repository.CreateGDPRRole(gdprRoleName != null ? gdprRoleName : identityRoleName);
                        //rc += resCnt;
                        //if (res.IsSuccess())
                        //{
                        //   rc.SetResult(true);
                        //}
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(3160303, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
                }
            }
            if (rc.IsError())
            {
                //var role = await roleManager.FindByNameAsync(identityRoleName);
                //if (role != null)
                //    await roleManager.DeleteAsync(role);
            }
            return(rc);
        }
Пример #30
0
        public async Task <IActionResult> OnGetAsync()
        {
            MxReturnCode <IActionResult> rc = new MxReturnCode <IActionResult>("Index.OnGetAsync()", Page());

            var userID = "[nobody logged-in]";
            var msg    = "unknown error";

            try
            {
                var loggedInUser = await _userManager.GetUserAsync(User);

                userID = loggedInUser?.Id ?? "[nobody logged-in]";
                msg    = $"{loggedInUser?.UserName ?? "nobody"} is logged-in. ";
                if (loggedInUser?.EmailConfirmed == false)
                {
                    msg += "Check your emails to complete your registration";
                }

                using (IAdminRepo repo = new AdminRepo(_config?.GetConnectionString("DefaultConnection")))
                {
                    var resCnt = await repo.GetUrdCountAsync();

                    rc += resCnt;
                    if (rc.IsError())
                    {
                        DatabaseStatus = "Database access failed";
                    }
                    else
                    {
                        DatabaseStatus = $"Database access ok, Role Count = {resCnt.GetResult()}";
                        rc.SetResult(Page());
                    }
                }
            }
            catch (Exception e)
            {
                rc.SetError(3040101, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
            }
            if (rc.IsError(true))
            {
                SetPageStatusMsg(rc.GetErrorUserMsgHtml(userID), ExistingMsg.Overwrite);
            }
            else
            {
                SetPageStatusMsg(msg, ExistingMsg.Overwrite);
            }

            return(rc.GetResult());
        }