public HttpResponseMessage AddRentalAgreement(AddRentalAgreement sd)
        {
            //  var httpRequest = HttpContext.Current.Request;

            RENTAL_AGREEMENT rentalAgreement = new RENTAL_AGREEMENT();
            Random           random          = new Random();



            //Save to DB
            try
            {
                rentalAgreement.CLIENTID       = sd.ClientID;
                rentalAgreement.PROPERTYID     = sd.PropertyID;
                rentalAgreement.RENTALSTATUSID = 1;
                rentalAgreement.REFERENCE_NO   = random.Next(100000, 999999).ToString();
                rentalAgreement.AMOUNTDUE      = db.RENTALAMOUNTs.Where(zz => zz.PROPERTYID == sd.PropertyID).Select(zz => zz.AMOUNT).FirstOrDefault();

                rentalAgreement.RENTALSTARTDATE = db.RENTALAPPLICATIONs.Where(xx => xx.CLIENTID == sd.RentalApplicationID).Select(ss => ss.PREFERREDSTARTDATE).FirstOrDefault();
                rentalAgreement.RENTALENDDATE   = DateTime.Now.AddYears(1);

                //change status of rental application to accepted here |||
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Booking "));
            }



            try
            {
                db.RENTAL_AGREEMENT.Add(rentalAgreement);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Rental "));
            }


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
        public HttpResponseMessage AddRentalAgreement(AddRentalAgreement sd)
        {
            //  var httpRequest = HttpContext.Current.Request;

            RENTAL_AGREEMENT  rentalAgreement = new RENTAL_AGREEMENT();
            RENTALAPPLICATION rentalAppl      = new RENTALAPPLICATION();
            PROPERTY          prop            = new PROPERTY();
            Random            random          = new Random();

            prop = db.PROPERTies.Find(sd.PropertyID);



            //Save to DB
            try
            {
                rentalAgreement.CLIENTID       = sd.ClientID;
                rentalAgreement.PROPERTYID     = sd.PropertyID;
                rentalAgreement.RENTALSTATUSID = 1;
                var REFERENCE_NO = random.Next(100000, 999999).ToString();
                rentalAgreement.REFERENCE_NO        = REFERENCE_NO;
                rentalAgreement.AMOUNTDUE           = db.RENTALAMOUNTs.Where(zz => zz.PROPERTYID == sd.PropertyID).Select(zz => zz.AMOUNT).FirstOrDefault();
                rentalAgreement.RENTALAPPLICATIONID = sd.RentalApplicationID;
                rentalAgreement.RENTALSTARTDATE     = DateTime.Today;
                rentalAgreement.DepositDueDate      = DateTime.Today.AddDays(7);

                //db.RENTALAPPLICATIONs.Where(xx=>xx.CLIENTID==sd.RentalApplicationID).Select(ss=>ss.PREFERREDSTARTDATE).FirstOrDefault();
                rentalAgreement.RENTALENDDATE = DateTime.Now.AddYears(1);
                db.RENTAL_AGREEMENT.Add(rentalAgreement);
                db.SaveChanges();


                var theClient = db.CLIENTs.Where(hh => hh.CLIENTID == sd.ClientID).FirstOrDefault();
                var agreement = db.RENTAL_AGREEMENT.Where(hh => hh.REFERENCE_NO == REFERENCE_NO).FirstOrDefault();
                var address   = db.PROPERTies.Where(hh => hh.PROPERTYID == sd.PropertyID).Select(jj => jj.ADDRESS).FirstOrDefault
                                    ();

                //send email with verification
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(theClient.EMAIL);
                mail.Subject = "Inturbidus: New Rental Agreement for " + theClient.NAME + " " + theClient.SURNAME;
                mail.Body    = "Good day " + theClient.NAME + " " + theClient.SURNAME + "\n Here are you new rental agreement details:\n Rental Agreement Reference No:" + agreement.REFERENCE_NO + "\n  Property Address:" + address + "\nDetails regarding a move-in inspection will be sent once the deposit is paid. Please pay the deposit on our site within 7 days (by " + agreement.DepositDueDate + " ) or else the rental agreement will be reverted. \n Please dont hesitate contact us should you have any queries.  \n\nHave a good day! ";
                //" \nRental Agreement Duration " + agreement.RENTALSTARTDATE + "-" + agreement.RENTAL
                SmtpServer.Port                  = 587;
                SmtpServer.DeliveryMethod        = SmtpDeliveryMethod.Network;
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "test123@123test");
                SmtpServer.EnableSsl             = true;

                SmtpServer.Send(mail);
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Booking "));
            }



            try
            {
                //change status of rental application to accepted here |||

                rentalAppl = db.RENTALAPPLICATIONs.Find(sd.RentalApplicationID);
                rentalAppl.RENTALAPPLICATIONSTATUSID = 5;
                prop.PROPERTYSTATUSID = 2;


                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Rental "));
            }


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }