コード例 #1
0
 public void Update(PropertyModel model)
 {
     PropertyType = model.PropertyType;
     SquareFeet = model.SquareFeet;
     NumberOfBedrooms = model.NumberOfBedrooms;
     NumberOfBathrooms = model.NumberOfBathrooms;
     NumberOfVehicles = model.NumberOfVehicles;
     
 }
コード例 #2
0
 public void Update(PropertyModel model)
 {
     PropertyId = model.PropertyId;
     AddressId = model.AddressId;
     PropertyName = model.PropertyName;
     SquareFeet = model.SquareFeet;
     NumberOfBedrooms = model.NumberOfBedrooms;
     NumberOfBathrooms = model.NumberOfBathrooms;
     NumberOfVehicles = model.NumberOfVehicles;
 }
コード例 #3
0
 public void Update(PropertyModel property)
 {
     PropertyName = property.PropertyName;
     SquareFeet = property.SquareFeet;
     NumberOfBedrooms = property.NumberOfBedrooms;
     NumberOfBathrooms = property.NumberOfBathrooms;
     NumberOfVehicles = property.NumberOfVehicles;
     HasOutdoorSpace = property.HasOutdoorSpace;
     Address.Update(property.Address);
 }
コード例 #4
0
 public void Update(PropertyModel modelProperty)
 {
     PropertyId = modelProperty.PropertyId;
     AddressId = modelProperty.AddressId;
     PropertyName = modelProperty.PropertyName;
     SquareFeet = modelProperty.SquareFeet;
     NumberOfBedrooms = modelProperty.NumberOfBedrooms;
     NumberOfBathrooms = modelProperty.NumberOfBathrooms;
     NumberOfVehicles = modelProperty.NumberOfVehicles;
     HasOutdoorSpace = modelProperty.HasOutdoorSpace;
 }
コード例 #5
0
        public IHttpActionResult PostProperty(PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbProperty = new Property(property);

            db.Properties.Add(dbProperty);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = property.PropertyId }, property);
        }
コード例 #6
0
        public IHttpActionResult PutProperty(int id, PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != property.PropertyId)
            {
                return BadRequest();
            }

            #region Thing to change

            Property dbProperty = db.Properties.FirstOrDefault(p => p.User.UserName == User.Identity.Name && p.PropertyId == id);

            if(dbProperty == null)
            {
                return BadRequest();
            }

            dbProperty.Update(property);
            db.Entry(dbProperty).State = EntityState.Modified;

            #endregion Thing to change

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #7
0
 public Property(PropertyModel model)
 {
     this.Update(model);
 }
コード例 #8
0
        public IHttpActionResult PutProperty(int id, PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != property.PropertyId)
            {
                return BadRequest();
            }

            var dbProperty = db.Properties.Find(id);

            dbProperty.Update(property);
            db.Entry(dbProperty).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #9
0
        public IHttpActionResult PostProperty(PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            var dbProperty = new Property(property);

            dbProperty.User = (PropertyManagerUser) db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            db.Properties.Add(dbProperty);
            db.SaveChanges();

            property.PropertyId = dbProperty.PropertyId;

            return CreatedAtRoute("DefaultApi", new { id = dbProperty.PropertyId }, Mapper.Map<PropertyModel>(property));
        }
コード例 #10
0
        public IHttpActionResult PutProperty(int id, PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != property.PropertyId)
            {
                return BadRequest();
            }

            // find address in database by ID and assign it to dbAddress variable
            // var dbProperty = db.Properties.Find(id);

            Property dbProperty = db.Properties.FirstOrDefault(p => p.User.UserName == User.Identity.Name && p.PropertyId == id);

            if(dbProperty == null)
            {
                return BadRequest();
            }

            // updates dbProperty with information passed in by property
            dbProperty.Update(property);

            // changes entity state to modified to let database know it has been changed
            db.Entry(dbProperty).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #11
0
 public Property(PropertyModel model)
 {
     this.Address = new Address(); 
     this.Update(model);
 }
コード例 #12
0
        public IHttpActionResult PostProperty(PropertyModel property)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbProperty = new Property();

            // User in this case is the token, not the user
            dbProperty.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            dbProperty.Update(property);

            db.Properties.Add(dbProperty);
            db.SaveChanges();

            property.PropertyId = dbProperty.PropertyId;

            return CreatedAtRoute("DefaultApi", new { id = property.PropertyId }, property);
        }
コード例 #13
0
 public Property(PropertyModel property)
 {
     this.Address = new Address();
     this.Update(property);
 }