Skip to content

Instantly share code, notes, and snippets.

@tibinthomas
Created March 15, 2017 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tibinthomas/92792657c8da36ab6721272557c5af39 to your computer and use it in GitHub Desktop.
Save tibinthomas/92792657c8da36ab6721272557c5af39 to your computer and use it in GitHub Desktop.
Error at _context.SaveChanges();
[HttpPost]
public ViewResult Save(Customer customer )
{
if (customer.Id == 0)
{
_context.Customers.Add(customer);
}
else
{
var customerInDB = _context.Customers.Single(c => c.Id == customer.Id);
//TryUpdateModel(customer, "", new String[] {"Name", "Email"} );
//Mapper.Map(customer, customerinDb)
customerInDB.Name = customer.Name;
customerInDB.Birthdate = customer.Birthdate;
customerInDB.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter;
customerInDB.MembershipType = customer.MembershipType;
_context.SaveChanges();
}
_context.SaveChanges();
RedirectToAction("Index", "Customers");
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment