public void AddAADetailsToDB(DetailAdderRequest request)
        {
            var DBinserter = new DatabaseInserter();

            int currentId = DBinserter.InsertData("email, firstname, surname, phone, previous_level, comments", $"{request.Contact.EmailAddress}', '{request.Contact.FirstName}', '{request.Contact.Surname}', '{request.Contact.ContactNumber}', '{request.Contact.Qualification}', '{request.Contact.Comment}", "Contact", "webform");

            DBinserter.InsertCheckboxData(request, currentId);
        }
        public int InsertCheckboxData(DetailAdderRequest request, int currentId)
        {
            int           newId            = 0;
            string        connectionstring = null;
            SqlConnection connection;
            SqlCommand    command;
            StringBuilder sql = new StringBuilder();
            SqlDataReader dataReader;

            connectionstring = $@"Data Source=LAPTOP-7GM05PUF;Initial Catalog=webform; Integrated Security=True;";
            sql.Append($"update Contact set ");
            sql.Append($"agriculture = '{request.Contact.Agriculture}',");
            sql.Append($"business = '{request.Contact.Business}',");
            sql.Append($"care = '{request.Contact.Care}',");
            sql.Append($"catering = '{request.Contact.Catering}',");
            sql.Append($"construction = '{request.Contact.Construction}',");
            sql.Append($"creative = '{request.Contact.Creative}',");
            sql.Append($"digital = '{request.Contact.Digital}',");
            sql.Append($"education = '{request.Contact.Education}',");
            sql.Append($"engineering = '{request.Contact.Engineering}',");
            sql.Append($"hair = '{request.Contact.Hair}',");
            sql.Append($"health = '{request.Contact.Health}',");
            sql.Append($"legal = '{request.Contact.Legal}',");
            sql.Append($"protective = '{request.Contact.Protective}',");
            sql.Append($"sales = '{request.Contact.Sales}',");
            sql.Append($"transport = '{request.Contact.Transport} '");
            sql.Append($"where id = {currentId} ");
            sql.Append("select scope_identity()");
            connection = new SqlConnection(connectionstring);
            try
            {
                connection.Open();
                command    = new SqlCommand(sql.ToString(), connection);
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    newId = Convert.ToInt32(dataReader.GetDecimal(0));
                }
                dataReader.Close();
                command.Dispose();
                connection.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can not open connection!");
            }
            return(newId);
        }
        private void AddContactDetails(DetailAdderRequest AdderRequest)
        {
            var client = new RestClient("https://localhost:44364/api/Apprenticeship/AddDetailsToDB");

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader("ApiKey", "Th4ZbP42RkOnrT47AqEt");
            request.AddParameter("application/json", ParameterType.RequestBody);
            string json = JsonConvert.SerializeObject(AdderRequest);

            request.AddParameter("application/json",
                                 json +
                                 "\r\n", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);
        }
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                var contact = new ContactModel();
                var request = new DetailAdderRequest();

                contact.EmailAddress  = EmailAddress;
                contact.Comment       = Comment;
                contact.FirstName     = FirstName;
                contact.Surname       = Surname;
                contact.ContactNumber = ContactNumber;
                contact.Qualification = Qualification;
                contact.Comment       = Comment;
                contact.ContactNumber = ContactNumber;

                //checkbox properties

                contact.Agriculture  = Agriculture ? 1 : 0;
                contact.Business     = Business ? 1 : 0;
                contact.Care         = Care ? 1 : 0;
                contact.Catering     = Catering ? 1 : 0;
                contact.Construction = Construction ? 1 : 0;
                contact.Creative     = Creative ? 1 : 0;
                contact.Digital      = Digital ? 1 : 0;
                contact.Education    = Education ? 1 : 0;
                contact.Engineering  = Engineering ? 1 : 0;
                contact.Hair         = Hair ? 1 : 0;
                contact.Health       = Health ? 1 : 0;
                contact.Legal        = Legal ? 1 : 0;
                contact.Protective   = Protective ? 1 : 0;
                contact.Sales        = Sales ? 1 : 0;
                contact.Transport    = Transport ? 1 : 0;

                request.Contact = contact;

                AddContactDetails(request);

                return(RedirectToPage("/FormResult", new { FirstName }));
            }

            return(Page());
        }