コード例 #1
0
        public IHttpActionResult PostAddress(AddressesModel address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var add = new Address(address);

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

            address.AddressId = add.AddressId;

            return CreatedAtRoute("DefaultApi", new { id = address.AddressId }, address);
        }
コード例 #2
0
ファイル: Address.cs プロジェクト: cduflo/18-PropertyManager
 public void Update(AddressesModel a)
 {
     AddressId = a.AddressId;
     Address1 = a.Address1;
     Address2 = a.Address2;
     Address3 = a.Address3;
     Address4 = a.Address4;
     Address5 = a.Address5;
     City = a.City;
     Region = a.Region;
     PostCode = a.PostCode;
     International = a.International;
 }
コード例 #3
0
        public IHttpActionResult PutAddress(int id, AddressesModel address)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            //grab entry from db
            var dbAddress = db.Addresses.Find(id);
            //save entry fetched
            dbAddress.Update(address);
            //mark entry as modified
            db.Entry(dbAddress).State = EntityState.Modified;
            //save changes
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddressExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #4
0
ファイル: Address.cs プロジェクト: cduflo/18-PropertyManager
 public Address(AddressesModel model)
 {
     this.Update(model);
 }