Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        public async void CRUDFirstRole()
        {
            var resCnt = await _repo.Db.GetRoleCountAsync();

            Assert.Equal(0, resCnt.GetResult());
            //Create
            var resDone = await _repo.Db.CreateRoleAsync("first role", 1, "purpose", "description");

            Assert.True(resDone.GetResult());

            resCnt = await _repo.Db.GetRoleCountAsync();

            Assert.Equal(1, resCnt.GetResult());
            //Read
            var resRole = await _repo.Db.GetRoleAsync("first role");

            GdprUrd role = resRole.GetResult();

            Assert.NotNull(role);
            Assert.Equal("first role", role.Name);
            Assert.Equal(1, role.RoleCode);
            Assert.Equal("purpose", role.Purpose);
            Assert.Equal("description", role.Description);
            Assert.Equal((int)GdprUrd.StatusVal.NotImplemented, role.Status);

            //Update
            resDone = await _repo.Db.UpdateRoleAsync(role, "changed role", 10, "changed purpose", "changed description", GdprUrd.StatusVal.Published);

            Assert.True(resDone.GetResult());

            resRole = await _repo.Db.GetRoleAsync("changed role");

            role = resRole.GetResult();

            Assert.NotNull(role);
            Assert.Equal("changed role", role.Name);
            Assert.Equal(10, role.RoleCode);
            Assert.Equal("changed purpose", role.Purpose);
            Assert.Equal("changed description", role.Description);
            Assert.Equal((int)GdprUrd.StatusVal.Published, role.Status);

            //Delete
            resDone = await _repo.Db.DeleteRoleAsync(role);

            Assert.True(resDone.GetResult());
        }
Example #4
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);
        }
Example #5
0
        public async Task <MxReturnCode <bool> > AssignRoleAsync(GdprUrd role, GdprRpd user)
        {
            var res = await db.QuerySingleAsync <int>("SELECT COUNT(*) FROM GdprUrd;");

            throw new NotImplementedException();
        }
Example #6
0
        public async Task <MxReturnCode <List <GdprWst> > > GetWebsiteTermsForRole(GdprUrd role)
        {
            var res = await db.QuerySingleAsync <int>("SELECT COUNT(*) FROM GdprUrd;");

            throw new NotImplementedException();
        }
Example #7
0
        public async Task <MxReturnCode <List <GdprRpd> > > GetUsersWithRoleAsync(GdprUrd role)
        {
            var res = await db.QuerySingleAsync <int>("SELECT COUNT(*) FROM GdprUrd;");

            throw new NotImplementedException();
        }
Example #8
0
        public async Task <MxReturnCode <bool> > CreateUrdAsync(string name, int roleCode, UrdStatus roleStatus, string purpose, string description, Guid wstId)
        {
            MxReturnCode <bool> rc = new MxReturnCode <bool>("AdminRepository.CreateUrdAsync()");

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(purpose) || string.IsNullOrWhiteSpace(description) || (GdprUrd.IsValidRoleCode(roleCode) == false) || (wstId == Guid.Empty))
            {
                rc.SetError(1010201, MxError.Source.Param, $"name={name ?? "[null]"} or purpose or description null or empty, or roleCode {roleCode} is invalid, or wstId is empty");
            }
            else
            {
                try
                {
                    if ((rc += CheckConnection()).IsSuccess())
                    {
                        GdprUrd role = new GdprUrd
                        {
                            Name        = name,
                            RoleCode    = roleCode,
                            Purpose     = purpose,
                            Description = description,
                            Status      = (int)roleStatus
                        };
                        var sql =
                            "INSERT INTO GdprUrd(Name, RoleCode, Status, Purpose, Description) VALUES(@Name, @RoleCode, @Status, @Purpose, @Description);";
                        var resultCreateUrd = await db.ExecuteAsync(sql, role);

                        if (resultCreateUrd != 1)
                        {
                            rc.SetError(1010202, MxError.Source.Data, $"unable to create role={name}");
                        }
                        else
                        {
                            var resGetUrd = await GetUrdAsync(name);

                            rc += resGetUrd;
                            if ((rc.IsError()) || (resGetUrd.GetResult() == null))
                            {
                                rc.SetError(1010203, MxError.Source.Data, $"unable to access new role={name}");
                            }
                            {
                                GdprWxr wxr = new GdprWxr
                                {
                                    UrdId = resGetUrd.GetResult().Id,
                                    WstId = wstId
                                };
                                sql = "INSERT INTO GdprWxr(@UrdId, WstId) VALUES(@UrdId, @WstId);";
                                var resultCreateWxr = await db.ExecuteAsync(sql, wxr);

                                if (resultCreateWxr != 1)
                                {
                                    rc.SetError(1010204, MxError.Source.Data, $"unable to create WXR for role={name}, WstId={wstId}");
                                }
                                else
                                {
                                    rc.SetResult(true);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    rc.SetError(1010205, MxError.Source.Exception, e.Message, MxMsgs.MxErrDbQueryException);
                }
            }
            return(rc);
        }
Example #9
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);
        }