public async Task <IHttpActionResult> PutAgency(int id, AgencyModel agencyModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != agencyModel.Id) { return(BadRequest()); } db.Entry(agencyModel).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AgencyModelExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "Id,Type,Name,Address,Latitude,Longitude,Description,WebsiteUrl,Contact,Email")] AgencyModel agency) { if (ModelState.IsValid) { db.Entry(agency).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("SaveToFirebase", new { aid = agency.Id })); } return(View(agency)); }
public bool Delete(int id) { try { _agencyDbContext.Entry(new Agency { Id = id }).State = EntityState.Deleted; _agencyDbContext.SaveChanges(); } catch (System.Exception) { return(false); } return(true); }
//ИНКАПСУЛЯЦИЯ: public void Save(ModelType model) { if (model.Id > 0) { var old = _dbSet.Find(model.Id); if (old != null) { _agencyDbContext.Entry(old).State = EntityState.Detached; } //doesn't work (doesn't change Company when saving User) //_agencyDbContext.Entry(model).State = EntityState.Modified; _dbSet.Update(model); } else { _dbSet.Add(model); } _agencyDbContext.SaveChanges(); }
public void UpdateAgency(Agency agency) { _context.Entry(agency).State = EntityState.Modified; _context.SaveChanges(); }