public IHttpActionResult PutLease(int id, Lease lease)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != lease.LeaseId)
            {
                return BadRequest();
            }

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostLease(Lease lease)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Leases.Add(lease);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease);
        }
        static void Main(string[] args)
        {
            var property = new Property();
            var tenant   = new Tenant();

            var lease = new Lease();

            lease.Property = property;
            lease.Tenant   = tenant;

            Console.WriteLine(property.Leases.Count == 1);
            Console.WriteLine(tenant.Leases.Count == 1);

            List <string> tenantNames = new List <string>();

            foreach (var l in property.Leases)
            {
                tenantNames.Add(lease.Tenant.FirstName + " " + lease.Tenant.LastName);
            }
        }
        static void Main(string[] args)
        {
            var property = new Property();
            var tenant = new Tenant();

            var lease = new Lease();

            lease.Property = property;
            lease.Tenant = tenant;

            Console.WriteLine(property.Leases.Count == 1);
            Console.WriteLine(tenant.Leases.Count == 1);

            List<string> tenantNames = new List<string>();

            foreach (var l in property.Leases)
            {
                tenantNames.Add(lease.Tenant.FirstName + " " + lease.Tenant.LastName);
            }
        }
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbLease = new Lease(lease);
            dbLease.Property.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            db.Leases.Add(dbLease);
            db.SaveChanges();

            lease.LeaseId = dbLease.LeaseId;

            return CreatedAtRoute("DefaultApi", new { id = dbLease.LeaseId }, lease);
        }
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbLease = new Lease();

            // Lease doesn't need the following code in POST because it's not being created directly by the user
            // dbLease.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

            dbLease.Update(lease);

            db.Leases.Add(dbLease);
            db.SaveChanges();

            lease.LeaseId = dbLease.LeaseId;

            return CreatedAtRoute("DefaultApi", new { id = lease.LeaseId }, lease);
        }