public void Update(PropertyModel model)
 {
     PropertyType = model.PropertyType;
     SquareFeet = model.SquareFeet;
     NumberOfBedrooms = model.NumberOfBedrooms;
     NumberOfBathrooms = model.NumberOfBathrooms;
     NumberOfVehicles = model.NumberOfVehicles;
     
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
        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);
        }
        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);
        }
Ejemplo n.º 7
0
 public Property(PropertyModel model)
 {
     this.Update(model);
 }
        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);
        }
        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));
        }
        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);
        }
 public Property(PropertyModel model)
 {
     this.Address = new Address(); 
     this.Update(model);
 }
        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);
        }
Ejemplo n.º 13
0
 public Property(PropertyModel property)
 {
     this.Address = new Address();
     this.Update(property);
 }