示例#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 <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);
        }
示例#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> > 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);
        }
示例#7
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);
        }
示例#8
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());
        }
示例#9
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);
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
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());
        }
示例#15
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);
        }
示例#16
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);
        }
示例#17
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);
        }
示例#18
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());
        }
示例#19
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());
        }
示例#20
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);
        }
示例#21
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);
        }
示例#22
0
        public async Task <MxReturnCode <bool> > CreateRoleAsync(string name, int rolecode, string purpose, string description)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.CreateRoleAsync()");

            if ((String.IsNullOrWhiteSpace(name)) || (GdprUrd.IsValidRoleCode(rolecode) == false) || (String.IsNullOrWhiteSpace(purpose)) || (String.IsNullOrWhiteSpace(description)))
            {
                rc.SetError(1020101, MxError.Source.Param, "invalid name, rolecode, purpose, description");
            }
            else
            {
                try
                {
                    //ASPNETRole ID,
                    //Get WST from Title
                    //Create WXR

                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        GdprUrd role = new GdprUrd
                        {
                            Name        = name,
                            RoleCode    = rolecode,
                            Purpose     = purpose,
                            Description = description,
                            Status      = (int)GdprUrd.StatusVal.NotImplemented
                        };
                        var sql = "INSERT INTO GdprUrd(Name, RoleCode, Status, Purpose, Description) VALUES(@Name, @RoleCode, @Status, @Purpose, @Description);";
                        var res = await db.ExecuteAsync(sql, role);

                        if (res != 1)
                        {
                            rc.SetError(1020102, MxError.Source.Data, String.Format("invalid record data {0}", role.ToString()));
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020103, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
示例#23
0
        static async Task <int> Main(string[] args)  //03-12-18 made async and returns int not void
        {
            MxUserMsg.Init(Assembly.GetExecutingAssembly(), MxMsgs.SupportedCultures);
            MxReturnCode <int> rc = new MxReturnCode <int>("Main()", -1, "*****@*****.**");

            try                                                     //03-12-18
            {
                IWebHost host = CreateWebHostBuilder(args).Build(); //calls Startup.ConfigureServices()
                using (var scope = host.Services.CreateScope())
                {
                    var services = scope.ServiceProvider;
                    if (services == null)
                    {
                        rc.SetError(3130101, MxError.Source.Sys, "scope.ServiceProvider is null");
                    }
                    else
                    {
                        var userManager = services.GetRequiredService <UserManager <IdentityUser> >();
                        var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >();
                        var config      = services.GetRequiredService <IConfiguration>();
                        if ((userManager == null) || (roleManager == null) || (config == null))
                        {
                            rc.SetError(3130102, MxError.Source.Sys, "userManager or roleManager or config is null");
                        }
                        else
                        {
                            var result = await SeedDb.EnsureDataPresentAsync(config, userManager, roleManager);

                            rc += result;
                            if (result.IsSuccess())
                            {
                                host.Run();         //calls Startup.Configure()
                                rc.SetResult(0);    //success - webapp has completed
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                rc.SetError(3010103, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
            }
            return(rc.GetResult());  //03-12-18
        }
示例#24
0
        public async Task <MxReturnCode <bool> > DeleteWstAsync(string title)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>($"ControllerRepository.DeleteWstAsync({title ?? "[null]"})", false);

            if (string.IsNullOrWhiteSpace(title))
            {
                rc.SetError(1020301, MxError.Source.Param, "role is null");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        var sqlFind = "SELECT * FROM GdprWst WHERE Title = @Title";
                        var resFind = await db.QuerySingleOrDefaultAsync <GdprWst>(sqlFind, new { Title = title });

                        if (resFind == null)
                        {
                            rc.SetError(1020302, MxError.Source.Data, $"{title} not found");
                        }
                        else
                        {
                            var sql = "DELETE FROM GdprWst WHERE Id = @Id";
                            var res = await db.ExecuteAsync(sql, new { Id = resFind.Id });

                            if (res != 1)
                            {
                                rc.SetError(1020303, MxError.Source.Data, $"Wst record not deleted Id={resFind.Id}, title={title}");
                            }
                            else
                            {
                                rc.SetResult(true);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020304, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
示例#25
0
        static async Task <int> Main(string[] args)  //03-12-18 made async and returns int not void
        {
            MxReturnCode <int> rc = new MxReturnCode <int>("Main()", -1);

            try
            {
                IWebHost host = CreateWebHostBuilder(args).Build();      //calls Startup.ConfigureServices()
                using (var scope = host?.Services?.CreateScope())
                {
                    var services = scope.ServiceProvider;
                    if (services == null)
                    {
                        rc.SetError(3050101, MxError.Source.Sys, "scope.ServiceProvider is null");
                    }
                    else
                    {
                        var mxIdentitySeedDb = services.GetRequiredService <IMxIdentitySeedDb>();
                        if (mxIdentitySeedDb == null)
                        {
                            rc.SetError(3050102, MxError.Source.Sys, "mxIdentityDb is null");
                        }
                        else
                        {
                            rc = await mxIdentitySeedDb.SetupAsync();

                            if (rc.IsSuccess(true))
                            {
                                host.Run();      //calls Startup.Configure()
                                rc.SetResult(0); //success - webapp has completed
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                rc.SetError(3050103, MxError.Source.Exception, e.Message, MxMsgs.MxErrUnknownException, true);
            }
            return(rc.GetResult());
        }
示例#26
0
        public async Task <MxReturnCode <bool> > CreateWstAsync(string title, string description, string url)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("ControllerRepository.CreateWstAsync()");

            if (String.IsNullOrWhiteSpace(title) || String.IsNullOrWhiteSpace(description) || String.IsNullOrWhiteSpace(url))
            {
                rc.SetError(1020201, MxError.Source.Param, $"invalid title={title ?? "[null]"} or null description or url");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        GdprWst terms = new GdprWst
                        {
                            Title  = title,
                            Status = (int)GdprWst.StatusVal.NotImplemented
                        };
                        var sql = "INSERT INTO GdprWst(Title, Status) VALUES(@Title,  @Status);";
                        var res = await db.ExecuteAsync(sql, terms);

                        if (res != 1)
                        {
                            rc.SetError(1020202, MxError.Source.Data, String.Format("invalid record data {0}", terms.ToString()));
                        }
                        else
                        {
                            rc.SetResult(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1020203, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
示例#27
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());
        }
示例#28
0
        public async Task <MxReturnCode <bool> > IsExistStdUrdAsync(string urdName)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepo.IsExistUrdAsync()");

            if (_adminRepo.GetStdGdprUrdCode(urdName) == UrdCodeStd.Undefined)
            {
                rc.SetError(1050101, MxError.Source.Param, $"name={urdName ?? "[null]"} is invalid");
            }
            else
            {
                rc += await _adminRepo.IsExistUrdAsync(urdName);
            }

            return(rc);
        }
示例#29
0
        public async Task <MxReturnCode <bool> > CreateStdUrdAsync(string urdName, Guid wstId)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("GdprSeedRepo.CreateUrdAsync()");

            var urdCode = _adminRepo.GetStdGdprUrdCode(urdName);

            if (urdCode == UrdCodeStd.Undefined)
            {
                rc.SetError(1050201, MxError.Source.Param, $"name={urdName ?? "[null]"} is invalid");
            }
            else
            {
                rc += await _adminRepo.CreateUrdAsync(urdName, (int)urdCode,
                                                      UrdStatus.PublishProduction,
                                                      _adminRepo.GetStdGdprUrdPurpose(urdCode),
                                                      _adminRepo.GetStdGdprUrdDescription(urdCode), wstId);
            }
            return(rc);
        }
示例#30
0
        public async Task <MxReturnCode <int> > GetRoleCountAsync()
        {
            MxReturnCode <int> rc = new MxReturnCode <int>("AdminRepository.GetRoleCountAsync()", -1);

            try
            {
                if ((rc += CheckConnection()).IsSuccess())
                {
                    var sql = "SELECT COUNT(*) FROM GdprUrd;";
                    var res = await db.QuerySingleAsync <int>(sql);

                    rc.SetResult(res);
                }
            }
            catch (Exception e)
            {
                rc.SetError(1020201, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
            }
            return(rc);
        }