Solved

ASP.NET MVC Error: must declare a body because it is not marked abstract

Posted on 2010-09-24
3
471 Views
Last Modified: 2012-05-10
Hi All,

I'm going through a book to help me learn ASP.NET MVC. I've got to a point where I seem to be getting errors, but I can't figure out why.

I have two classes, an IProductRepository and ProductRespository.

IProductRepository is this...

namespace ToyStore.Models
{
    public class IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}

and ProductRepository...

namespace ToyStore.Models
{
    public class ProductRepository : IProductRepository
    {
        private ProductsDBEntities _entities = new ProductsDBEntities();

        #region IProductRepository Members
        public IEnumerable<Product> List()
        {
            return _entities.ProductSet.ToList();
        }

        public Product Get(int Id)
        {
            return (from p in _entities.ProductSet where p.Id == Id select p).FirstOrDefault();
        }

        public void Create(Product productToCreate)
        {
            _entities.AddToProductSet(productToCreate);
            _entities.SaveChanges();
        }

        public void Edit(Product productToEdit)
        {
            var originalProduct = Get(productToEdit.Id);
            _entities.ApplyPropertyChanges(originalProduct.EntityKey.EntitySetName,productToEdit);
            _entities.SaveChanges();
        }

        public void Delete(Product productToDelete)
        {
            var originalProduct = Get(productToDelete.Id);
            _entities.DeleteObject(originalProduct);
            _entities.SaveChanges();
        }

        #endregion
    }
}


Does anyone have any ideas? I had a look around google, and a few results said to make sure that the project framework is 3.5, I've checked this, and it is.
0
Comment
Question by:SheppardDigital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 33753747
It's quite easy. You have defined a class where it should be an interface;

namespace ToyStore.Models
{
    public class IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}


should be:

namespace ToyStore.Models
{
    public interface IProductRepository
    {
        public IEnumerable<Product> List();  **ERROR ON THIS LINE**
        Product Get(int id);  **ERROR ON THIS LINE**
        void Create(Product productToCreate);  **ERROR ON THIS LINE**
        void Edit(Product productToEdit);  **ERROR ON THIS LINE**
        void Delete(Product productToDelete);  **ERROR ON THIS LINE**
    }
}

Open in new window

0
 
LVL 14

Expert Comment

by:existenz2
ID: 33753749
Without the **ERROR ON THIS LINE**   ofcourse :)
0
 

Author Closing Comment

by:SheppardDigital
ID: 33753782
Sometimes it takes someone else to take a look and pinpoint your errors :)

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Return array 3 33
CSS for Popup in ASP.NET 4 46
Adjust the codes 3 63
.Net remove carriage returns, line feeds and tabbs 5 35
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question