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

            BOOKING booking = new BOOKING();
            EMPLOYEEDATETIMESLOT bookingUpdate = new EMPLOYEEDATETIMESLOT();



            //Save to DB
            try
            {
                booking.CLIENTID   = sd.ClientID;
                booking.PROPERTYID = sd.PropertyID;
                booking.USERID     = 2;
                //   booking.CLIENTID = Convert.ToInt32(httpRequest["CLIENTID"]);
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Booking "));
            }


            try
            {
                db.BOOKINGs.Add(booking);
                db.SaveChanges();

                bookingUpdate = db.EMPLOYEEDATETIMESLOTs.Find(sd.EmployeeDateTimeSlotID);
                int value = int.Parse(db.BOOKINGs
                                      .OrderByDescending(p => p.BOOKINGID)
                                      .Select(r => r.BOOKINGID)
                                      .First().ToString());
                bookingUpdate.BOOKINGID           = value;
                bookingUpdate.EMPLOYEESLOTSTAUSID = 2;


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


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
        public HttpResponseMessage Addapplication(Addbooking sd)
        {
            INF370Entities db = new INF370Entities();

            db.Configuration.ProxyCreationEnabled = false;

            //  var httpRequest = HttpContext.Current.Request;

            RENTALAPPLICATION application = new RENTALAPPLICATION();



            //Save to DB
            try
            {
                application.CLIENTID = sd.ClientID;

                //application.USERID = 2;
                //   booking.CLIENTID = Convert.ToInt32(httpRequest["CLIENTID"]);
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error With Application "));
            }


            try
            {
                db.RENTALAPPLICATIONs.Add(application);
                db.SaveChanges();



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


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Ejemplo n.º 3
0
        public dynamic Addapplication(Addbooking sd)
        {
            INF370Entities db = new INF370Entities();

            db.Configuration.ProxyCreationEnabled = false;

            //  var httpRequest = HttpContext.Current.Request;

            RENTALAPPLICATION application = new RENTALAPPLICATION();



            //Save to DB
            try
            {
                application.CLIENTID = sd.ClientID;

                //application.USERID = 2;
                //   booking.CLIENTID = Convert.ToInt32(httpRequest["CLIENTID"]);
            }
            catch (Exception e)
            {
                return(false);
            }


            try
            {
                db.RENTALAPPLICATIONs.Add(application);
                db.SaveChanges();



                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(false);
            }


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(true);
        }
        public dynamic Addbooking(Addbooking sd)
        {
            //  var httpRequest = HttpContext.Current.Request;

            BOOKING booking = new BOOKING();
            EMPLOYEEDATETIMESLOT bookingUpdate = new EMPLOYEEDATETIMESLOT();



            //Save to DB
            try
            { var existing = db.BOOKINGs.Where(jj => jj.CLIENTID == sd.ClientID && jj.PROPERTYID == sd.PropertyID).ToList();


              if (existing.Count == 0)
              {
                  booking.CLIENTID   = sd.ClientID;
                  booking.PROPERTYID = sd.PropertyID;
                  var USERID = db.CLIENTs.Where(kk => kk.CLIENTID == sd.ClientID).Select(jj => jj.USERID).FirstOrDefault();
                  booking.USERID = USERID;
                  //   booking.CLIENTID = Convert.ToInt32(httpRequest["CLIENTID"]);
              }
              else
              {
                  dynamic setInvalid = new ExpandoObject();
                  setInvalid = false;
                  return(setInvalid);
              } }
            catch (Exception e)
            {
                return(false);
            }


            try
            {
                db.BOOKINGs.Add(booking);
                db.SaveChanges();

                bookingUpdate = db.EMPLOYEEDATETIMESLOTs.Find(sd.EmployeeDateTimeSlotID);
                int value = int.Parse(db.BOOKINGs
                                      .OrderByDescending(p => p.BOOKINGID)
                                      .Select(r => r.BOOKINGID)
                                      .First().ToString());
                bookingUpdate.BOOKINGID           = value;
                bookingUpdate.EMPLOYEESLOTSTAUSID = 2;


                db.SaveChanges();


                var emp       = db.EMPLOYEEs.Where(hh => hh.EMPLOYEEID == bookingUpdate.EMPLOYEEID).FirstOrDefault();
                var theClient = db.CLIENTs.Where(hh => hh.CLIENTID == sd.ClientID).FirstOrDefault();
                var prop      = db.PROPERTies.Where(hh => hh.PROPERTYID == sd.PropertyID).FirstOrDefault();
                var empslot   = bookingUpdate.DATETIMESLOTID;
                var dateid    = db.DATETIMESLOTs.Find(empslot);
                var date      = db.DATEs.Where(kk => kk.DATEID == dateid.DATEID).Select(jj => jj.DATEDESCRIPTION).FirstOrDefault();
                var slotS     = db.SLOTs.Where(kk => kk.SLOTID == dateid.SLOTID).FirstOrDefault();

                //send email with verification
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(emp.EMAIL);
                mail.Subject = "Property Viewing Booking From: " + theClient.NAME + " " + theClient.SURNAME + " " + theClient.PHONENUMBER;
                mail.Body    = "Good day " + emp.NAME + " " + emp.SURNAME + "\n" + theClient.NAME + " " + theClient.SURNAME + " would love to view the property at " + prop.ADDRESS + " with the property reference number " + prop.PROPERTYID + ". \nClient Details \nClient Name : " + theClient.NAME + " " + theClient.SURNAME + "\nClient Email:" + theClient.EMAIL + "\nClient Number:" + theClient.PHONENUMBER + "\nViewing Details \nDate and Time of viewing : " + date + " " + DateTime.Now.Year.ToString() + " \nFrom: " + slotS.STARTTIME + "-" + slotS.ENDTIME + " \n\nThank you  ";

                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)
            {
                return(false);
            }


            //booking.BOOKINGID = getCreatedBookingID(booking.CLIENTID);
            return(true);
        }