Does not implement interface member MVC

Happy Coconut

I can't make the Post Action to work. It gives me error over :IAuthorService in Services: This is my code below:

'AuthorService' does not implement intreface member 'IAuthorService.Post(AutthorViewModel)'.'IAuthorService.Post(AutthorViewModel)' cannot implement 'IAuthorService.Post(AutthorViewModel)' because it does not have the matching reurn type of 'AuthorViewModel'.

Author class:

namespace Entities
{
    public class Author
    {
        public Author()
        {
            Books = new List<Book>();
        }

        public int   ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }

        public List<Book> Books { get; set; }
    }
}

Interface:

namespace Interfaces.RepositoryIntefaces
{
    public interface IAuthorRepository
    {
        List<Author> GetAllFromRepo();
        void PostFromRepo(Author author);
    }
}

Repository:

namespace Repositories
{
    public class AuthorRepository : IAuthorRepository
    {
        AppContext myDB = new AppContext();
        public List<Author> GetAllFromRepo()
        {
           return myDB.Authors.Include(a=> a.Books).ToList();
        }

        public void PostFromRepo(Author author)
        {
            myDB.Authors.Add(author);
            myDB.SaveChanges();
        }
    }
}

Services:

namespace Services
{
    public class AuthorService : IAuthorService // here is the error
    {
        private  IAuthorRepository _AuthorRepository;

        public AuthorService(IAuthorRepository authorRepository)
        {
            _AuthorRepository = authorRepository;
        }
        public List<AuthorViewModel> GetAll()
        {
            List<Author> authors = _AuthorRepository.GetAllFromRepo();

            return authors.Select(x => new AuthorViewModel()
            {
                ID = x.ID,
                FirstName = x.FirstName,
                LastName = x.LastName,
                Books = x.Books.Select(g => new BookViewModel()
                {
                    ID = g.ID,
                    Name = g.Name
                }).ToList()
            }).ToList();
        }

        public void Post(AuthorViewModel author)
        {
            _AuthorRepository.PostFromRepo(new Author()
            {
                FirstName = author.FirstName,
                LastName = author.LastName,
                Books = new List<Book>()
            });
        }
    }
}

Author View Model:

namespace ViewModels
{
    public class AuthorViewModel
    {
        public AuthorViewModel()
        {
            Books = new List<BookViewModel>();  
        }
        public int ID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }

        public List<BookViewModel> Books { get; set; }
    }
}

Controllers:

namespace WebApp.Controllers
{
    public class HomeController : Controller
    {
        private readonly IAuthorService _AuthorService;

        public HomeController(IAuthorService authorService)
        {
            _AuthorService = authorService;
        }

        public ActionResult Index()
        {
            List<AuthorViewModel> Authors = _AuthorService.GetAll();
            return View(Authors.ToList());

        }

        [HttpPost]
        public ActionResult Create()
        {
           _AuthorService.Post(new AuthorViewModel() { FirstName = "Olivia", LastName = "Fox", Books = new List<BookViewModel>() });

            return View();
        }
    }
}

This is the error i get in error list in VS2017:

Severity Code Description Project File Line Suppression State Error CS0738 'AuthorService' does not implement interface member 'IAuthorService.Post(AuthorViewModel)'. 'AuthorService.Post(AuthorViewModel)' cannot implement 'IAuthorService.Post(AuthorViewModel)' because it does not have the matching return type of 'AuthorViewModel'. Services C:\Users\Jack\Desktop\WebApp Domasna 1.9\Services\AuthorService.cs 14 Active

the code for IAuthorService:

namespace Interfaces.ServiceInterfaces
{
    public interface IAuthorService
    {
        List<AuthorViewModel> GetAll();
        AuthorViewModel Post(AuthorViewModel author);
    }
}
Gaurav Jalan

I think this is straight forward. Your interface has return type of AuthorViewModel while your class has return type of void.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does not implement interface member issues

From Dev

Error: Does not implement interface member

From Dev

Error: Does not implement interface member

From Dev

Class does not implement interface member

From Dev

Error 1: does not implement interface member

From Dev

Fighter class does not implement interface member

From Dev

"Class does not implement interface member" error on class implementing a generic interface

From Dev

Implement interface in class or as member

From Dev

Xamarin jar binding error: Class does not implement interface member

From Dev

The "does not implement interface member" error when using inheritance

From Dev

Error when upgrading to WebAPI 2.1 XmlDocumentationProvider does not implement interface member GetDocumentation

From Dev

'Data.Repository.UnitofWork' does not implement interface member 'Data.Repository.IUnitofWork.Customer'

From Dev

Shared.CellItem' does not implement interface member 'System.IDisposable.Dispose()

From Dev

Cannot implement an interface member because it is not public

From Dev

"..." cannot implement an interface member because it is not public

From Dev

How to implement static interface member to WCF?

From Dev

How to implement an interface using class member?

From Dev

IEnumerator does not implement interface IEnumerable

From Dev

Resharper wants me to implement an interface member that is implemented in WPF generated code

From Dev

Member variable which must extend class A and implement some interface

From Dev

Resharper wants me to implement an interface member that is implemented in WPF generated code

From Dev

Member variable which must extend class A and implement some interface

From Dev

C# cs0660 error (implement interface member)

From Java

'append' called on an object that does not implement interface FormData

From Dev

Why does ArrayList implement RandomAccess Interface?

From Dev

How does Java implement interface polymorphism?

From Dev

'stepUp' called on an object that does not implement interface HTMLInputElement

From Dev

Visitor Pattern "does not implement interface" error

From Dev

Why does the ExecutorService interface not implement AutoCloseable?

Related Related

  1. 1

    Does not implement interface member issues

  2. 2

    Error: Does not implement interface member

  3. 3

    Error: Does not implement interface member

  4. 4

    Class does not implement interface member

  5. 5

    Error 1: does not implement interface member

  6. 6

    Fighter class does not implement interface member

  7. 7

    "Class does not implement interface member" error on class implementing a generic interface

  8. 8

    Implement interface in class or as member

  9. 9

    Xamarin jar binding error: Class does not implement interface member

  10. 10

    The "does not implement interface member" error when using inheritance

  11. 11

    Error when upgrading to WebAPI 2.1 XmlDocumentationProvider does not implement interface member GetDocumentation

  12. 12

    'Data.Repository.UnitofWork' does not implement interface member 'Data.Repository.IUnitofWork.Customer'

  13. 13

    Shared.CellItem' does not implement interface member 'System.IDisposable.Dispose()

  14. 14

    Cannot implement an interface member because it is not public

  15. 15

    "..." cannot implement an interface member because it is not public

  16. 16

    How to implement static interface member to WCF?

  17. 17

    How to implement an interface using class member?

  18. 18

    IEnumerator does not implement interface IEnumerable

  19. 19

    Resharper wants me to implement an interface member that is implemented in WPF generated code

  20. 20

    Member variable which must extend class A and implement some interface

  21. 21

    Resharper wants me to implement an interface member that is implemented in WPF generated code

  22. 22

    Member variable which must extend class A and implement some interface

  23. 23

    C# cs0660 error (implement interface member)

  24. 24

    'append' called on an object that does not implement interface FormData

  25. 25

    Why does ArrayList implement RandomAccess Interface?

  26. 26

    How does Java implement interface polymorphism?

  27. 27

    'stepUp' called on an object that does not implement interface HTMLInputElement

  28. 28

    Visitor Pattern "does not implement interface" error

  29. 29

    Why does the ExecutorService interface not implement AutoCloseable?

HotTag

Archive