public static void Save(ContactsViewModel model) { using (var db = new ShlekenEntities3()) { if (model.Id > 0) { var item = db.Contacts.Single(i => i.Projects.AccountId == Userservice.AccountId && i.Id == model.Id); item = model.Map <ContactsViewModel, Contacts>(item); db.SaveChanges(); } else { var item = model.Map <ContactsViewModel, Contacts>(); db.Contacts.Add(item); db.SaveChanges(); } } }