public bool Add(Agency model) { try { _agencyDbContext.Add(model); _agencyDbContext.SaveChanges(); } catch (System.Exception) { return(false); } return(true); }
public ActionResult Create([Bind(Include = "Id,Type,Name,Address,Latitude,Longitude,Description,WebsiteUrl,Contact,Email")] AgencyModel model) { var types = GetAllTypes(); var hospitals = GetAllHospitals(); var polices = GetAllPoliceDepartments(); var fires = GetAllFireStations(); model.Types = GetSelectListItems(types); model.Hospitals = GetSelectListItems(hospitals); model.PoliceDepartments = GetSelectListItems(polices); model.FireStations = GetSelectListItems(fires); if (ModelState.IsValid) { db.Agencies.Add(model); db.SaveChanges(); return(RedirectToAction("SaveToFirebase", new { aid = model.Id })); } return(View(model)); }
//ИНКАПСУЛЯЦИЯ: 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 InsertAgency(Agency agency) { _context.Agencies.Add(agency); _context.SaveChanges(); }
public void InsertAgent(Agent agent) { _context.Agents.Add(agent); _context.SaveChanges(); }