Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Inconsistent accessibility: return type xxx is less accessible than method xxx CS0050

16.02.2023 (πŸ‘6994)


 

In C# Asp.Net Core .Net 4 6 7 8

 

Fehlermeldung

CS0050

Inconsistent accessibility: return type 'Task<ActionResult<ArticlesController.EditItem_OutputModel>>' is less accessible than method 'ArticlesController.Save_Article(ArticlesController.EditItem_OutputModel)'

 

CS0051

Inconsistent accessibility: parameter type 'ArticlesController.EditItem_OutputModel' is less accessible than method 'ArticlesController.Save_Article(ArticlesController.EditItem_OutputModel)'

 

Problem:

Beim Verwenden einer Methode / Function wird eine Object / Klasse eingebettet, welche privat und nicht public deklariert ist

LΓΆsung:

Die class mit public class benennen

 

public class EditItem_OutputModel

        {

            public string guidarticle { get; set; } = string.Empty;

            public string title { get; set; } = string.Empty;

            ..

            ..

        }

 

        //=Update

        //*response with editmodel, to confirm new guid on new

        [HttpPost("save_article")]

        public async Task<ActionResult<EditItem_OutputModel>> Save_Article(EditItem_OutputModel article)

        {

            //*check

            if (article == null) return BadRequest("Article to save is empty");

 

            //*get matching Article from Database by ID

            ArticleDbModel? dbArticle;

            try

            {

                dbArticle = await _dbContext.tbl_Articles.FindAsync(article.guidarticle);

            }

 

 

 

public class EditItem_OutputModel

        {

            public string guidarticle { get; set; } = string.Empty;

            public string title { get; set; } = string.Empty;

            public string html { get; set; } = string.Empty;

            public string folder { get; set; } = string.Empty;

            public string keywords { get; set; } = string.Empty;

            public DateTime dateedit { get; set; } = DateTime.Now;

            public bool isowner { get; set; } = false;

        }

 

        //=Update

        //*response with editmodel, to confirm new guid on new

        [HttpPost("save_article")]

        public async Task<ActionResult<EditItem_OutputModel>> Save_Article(EditItem_OutputModel article)

        {

            //*check

            if (article == null) return BadRequest("Article to save is empty");

 

            //*get matching Article from Database by ID

            ArticleDbModel? dbArticle;

            try

            {

                dbArticle = await _dbContext.tbl_Articles.FindAsync(article.guidarticle);

            }

            catch (Exception e)

            {

                return BadRequest("Database error:" + e.Message);

                //throw;

            }

           

            //*check

            if (dbArticle == null) return BadRequest("Article not found");

 

            //< init.correction >

            string title=article.title;

            string keywords=article.keywords;

            string folder=article.folder;

            string html=article.html;

            //</ init.correction >

 

 

            dbArticle.Title = title;

            dbArticle.Folder=folder;

            dbArticle.Keywords = keywords;

            dbArticle.Html=html;

 

            dbArticle.DateEdit = DateTime.Now;

           

            await _dbContext.SaveChangesAsync();

 

            //*check

           

            //< Prepare Output >

            EditItem_OutputModel outEditItem = new EditItem_OutputModel();

            outEditItem.guidarticle = dbArticle.GuidArticle;

            outEditItem.title = dbArticle.Title ?? "";

            outEditItem.html = dbArticle.Html ?? "";

            outEditItem.folder = dbArticle.Folder ?? "";

            outEditItem.keywords = dbArticle.Keywords ?? "";

            outEditItem.dateedit = dbArticle.DateEdit;

            outEditItem.isowner = false; //init

            //</ Prepare Output >

 

            //< check_owner >

            //get client User to check if is owner

            var userGUID = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (userGUID == dbArticle.GuidUser)

            {

                outEditItem.isowner = true;

            }

            //</ check_owner >

 

            return Ok(outEditItem);  //with status           

        }