// Calculate the number of days in current month that are included between
        //   the input lease start date and end date
        private decimal daysInLeaseThisMonth(Lease lease)
        {
            DateTime today = DateTime.Now;

            // Lower day is the maximum of the first day of this month and the lease start date
            DateTime lowerDay = DateTimeExtensions.MaxDate
                                (DateTimeExtensions.FirstDayOfMonth(today), lease.StartDate);

            // If lease end date is not null, upper day is the minimum of the last day of this month
            //   and the lease end date
            // If lease end date is null, upper day is the last day of this month
            DateTime upperDay;
            if (lease.EndDate.HasValue)
            {
                DateTime endDate = lease.EndDate.GetValueOrDefault();
                upperDay = DateTimeExtensions.MinDate
                                        (DateTimeExtensions.LastDayOfMonth(today), endDate);
            }
            else
            {
                upperDay = DateTimeExtensions.LastDayOfMonth(today);
            }

            // Number of days in lease this month = upper day - lower day + 1
            return (upperDay - lowerDay).Days + 1;
        }
        public IHttpActionResult PostLease(LeaseModel lease)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbLease = new Lease();

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

            lease.LeaseId = dbLease.LeaseId;

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

            //Set up new Lease object,
            //  and populate it with the values from
            //  the input LeaseModel object
            Lease dbLease = new Lease();
            dbLease.Update(lease);

            // Add the new Lease object to the list of Lease objects
            db.Leases.Add(dbLease);

            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {

                throw new Exception("Unable to add the lease to the database.");
            }

            // Update the LeaseModel object with the new lease ID
            //  that was placed in the Lease object after the changes
            //  were saved to the DB
            lease.LeaseId = dbLease.LeaseId;
            return CreatedAtRoute("DefaultApi", new { id = dbLease.LeaseId }, lease);
        }