Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 3
0
        public bool Delete(int id)
        {
            try
            {
                _agencyDbContext.Entry(new Agency {
                    Id = id
                }).State = EntityState.Deleted;
                _agencyDbContext.SaveChanges();
            }
            catch (System.Exception)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
 public void UpdateAgency(Agency agency)
 {
     _context.Entry(agency).State = EntityState.Modified;
     _context.SaveChanges();
 }