示例#1
0
        public bool Add(Agency model)
        {
            try
            {
                _agencyDbContext.Add(model);
                _agencyDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        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));
        }
示例#3
0
        //ИНКАПСУЛЯЦИЯ:
        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();
        }
示例#4
0
 public void InsertAgency(Agency agency)
 {
     _context.Agencies.Add(agency);
     _context.SaveChanges();
 }
示例#5
0
 public void InsertAgent(Agent agent)
 {
     _context.Agents.Add(agent);
     _context.SaveChanges();
 }