Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apress Pro Asp.net MVC Framework 3 - SportsStore Edit Product not working?

G’day All, has anyone purchased the ALPHA of Apress Pro Asp.net MVC Framework 3 and created the SportsStore? I can’t for the life of me edit products and have the DB update successfully? No errors are displayed and unit tests all function, but no successful ‘edit’ i.e. I change some details, click save, it reports successful – I then check the results, and nothing has happened? Did anyone else find this when working through the SportsStore? Any advice will be greatly appreciated.

Cheers.

like image 560
MVC Newbie Avatar asked Jun 15 '11 08:06

MVC Newbie


1 Answers

The state of the EF object needs to be updated before saving.

public void SaveProduct(Product product)
        {
            if (product.ProductID == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                context.Entry(product).State = System.Data.EntityState.Modified;
            }


            int result = context.SaveChanges();

        }
like image 59
carrot_programmer_3 Avatar answered Jan 01 '23 09:01

carrot_programmer_3