public IHttpActionResult PutAddress(int id, AddressModel address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != address.AddressId)
            {
                return BadRequest();
            }

            db.Entry(address).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
 public void Update(AddressModel modelAddress)
 {
     Address1 = modelAddress.Address1;
     Address2 = modelAddress.Address2;
     Address3 = modelAddress.Address3;
     Address4 = modelAddress.Address4;
     Address5 = modelAddress.Address5;
     City = modelAddress.City;
     State = modelAddress.State;
     PostCode = modelAddress.PostCode;
     International = modelAddress.International; 
 }
Пример #3
0
 public void Update(AddressModel model)
 {
     AddressId = model.AddressId;
     Address1 = model.Address1;
     Address2 = model.Address2;
     Address3 = model.Address3;
     Address4 = model.Address4;
     Address5 = model.Address5;
     City = model.City;
     Region = model.Region;
     PostalCode = model.PostalCode;
     International = model.International;
 }
        public IHttpActionResult PostAddress(AddressModel address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbAddress = new Address(address);

            db.Addresses.Add(dbAddress);
            db.SaveChanges();

            address.AddressId = dbAddress.AddressId;

            return CreatedAtRoute("DefaultApi", new { id = address.AddressId }, address);
        }
        public IHttpActionResult PutAddress(int id, AddressModel modelAddress)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != modelAddress.AddressId)
            {
                return BadRequest();
            }

            // to be changed
            // db.Entry(address).State = EntityState.Modified;

            // 1. Grab the entry from the database
            var dbAddress = db.Addresses.Find(id);

            // 2. Update the entry fetched from the database
            dbAddress.Update(modelAddress);

            // 3. Mark entry as modified
            db.Entry(dbAddress).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
 public Address(AddressModel address)
 {
     this.Update(address);
 }
 public Address(AddressModel model)
 {
     this.Update(model);
 }
        public IHttpActionResult PutAddress(int id, AddressModel address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != address.AddressId)
            {
                return BadRequest();
            }
            #region
            //--reference 15-Kanban-API/cardcontroller
            //var dbAddress = db.Addresses.Find(id);
            //dbAddress.Update(address);
            db.Entry(address).State = EntityState.Modified;
            #endregion
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }