public void UpdateAdvert(Advert ad) { var existing = _ctx.Adverts.SingleOrDefault(em => em.Id == ad.Id); if (existing != null) { _ctx.Entry(existing).State = EntityState.Detached; _ctx.Adverts.Attach(ad); _ctx.Entry(ad).State = EntityState.Modified; _ctx.SaveChanges(); } }
//----------------------------- A D V E R T S ----------------------------------- public Advert CreateAdvert(Advert ad) { _ctx.Adverts.Add(ad); _ctx.SaveChanges(); return(ad); }