Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.51 KB | None | 0 0
  1. Future sendEmail(datiForm) async {
  2.     var body = Map<String, dynamic>();
  3.     var htmlToSend = '';
  4.     var extraInfo = '';
  5.     var corpoEmail = Map<String, dynamic>();
  6.  
  7.     if (datiForm is DatiFormStore) {
  8.       if (datiForm.problemaDaSegnalare == 'Prezzo Errato') {
  9.         extraInfo = "questo è l'ID dell'articolo ${datiForm.productId}";
  10.       }
  11.       htmlToSend = '''
  12.        <p style="font-size: 16px;">Form Compilato ${datiForm.email_object}</p>
  13.        <p>L'utente ha trovato un problema per quanto riguarda ${datiForm.problemaDaSegnalare} riguardo il seguente store ${datiForm.storeID} </p>
  14.         <p> messaggio: ${datiForm.message}</p>
  15.         <p>${extraInfo}</p>
  16. ''';
  17.      corpoEmail = datiForm.itemToJson(datiForm);
  18.      body = {
  19.        "bodyEmail": corpoEmail,
  20.        "email_object": datiForm.email_object,
  21.        "email": datiForm.email,
  22.        "htmlToSend": htmlToSend
  23.      };
  24.    }
  25.  
  26.    if (datiForm is DatiFormProduct) {
  27.      htmlToSend = '''
  28.         <p style="font-size: 16px;">Form Compilato ${datiForm.email_object}</p>
  29.         <p>L'utente ha trovato un problema per quanto riguarda ${datiForm.problemaDaSegnalare} riguardo il seguente prodotto ${datiForm.productId} </p>
  30.        <p> messaggio: ${datiForm.message}</p>      
  31. ''';
  32.       corpoEmail = datiForm.itemToJson(datiForm);
  33.  
  34.       body = {
  35.         "bodyEmail": corpoEmail,
  36.         "email_object": datiForm.email_object,
  37.         "email": datiForm.email,
  38.         "htmlToSend": htmlToSend
  39.       };
  40.     }
  41.     if (datiForm is DatiForm) {
  42.       if (datiForm.haveStore) {
  43.         extraInfo = '''                    
  44.            <li>nome dell'azienda: ${datiForm.company_name}</li>
  45.             <li>indirizzo dell'azienda: ${datiForm.companyAddress}</li>
  46.        ''';
  47.       }
  48.       htmlToSend = '''
  49.        <p style="font-size: 16px;">Form Compilato</p>
  50.                <br />
  51.                <ul>
  52.                    <li>nome utente: ${datiForm.name}</li>
  53.                    <li>email utente: ${datiForm.email}</li>
  54.                    <li>città: ${datiForm.city}</li>
  55.                    <li>messaggio dell'utente: ${datiForm.message}</li>
  56.                     ${extraInfo}
  57.                 </ul>
  58.       ''';
  59.  
  60.      corpoEmail = datiForm.itemToJson(datiForm);
  61.      body = {
  62.        "bodyEmail": corpoEmail,
  63.        "email_object": datiForm.email_object,
  64.        "email": datiForm.email,
  65.        "htmlToSend": htmlToSend
  66.      };
  67.    }
  68.  
  69.    const url =
  70.        'https://europe-west1-beonbuy-b3638.cloudfunctions.net/sendMail';
  71.     const header = {
  72.       'Accept': 'application/json',
  73.       'Content-Type': 'application/json',
  74.     };
  75.  
  76.     await http
  77.         .post(url, body: json.encode(body), headers: header)
  78.         .then((response) {
  79.       print(response.body);
  80.     });
  81.   }
  82.  
  83. class DatiForm {
  84.   var city,
  85.       companyAddress,
  86.       company_name,
  87.       email,
  88.       name,
  89.       message,
  90.       email_object = '';
  91.   var haveStore, acceptedPolicy = false;
  92.   DatiForm() {
  93.     city = '';
  94.     company_name = '';
  95.     companyAddress = '';
  96.     email = '';
  97.     name = '';
  98.     email_object = '';
  99.     haveStore = false;
  100.     acceptedPolicy = false;
  101.   }
  102.   Map<String, dynamic> itemToJson(DatiForm instance) {
  103.     return <String, dynamic>{
  104.       'City': instance.city,
  105.       'CompanyName': instance.company_name,
  106.       'CompanyAddress': instance.companyAddress,
  107.       'Name': instance.name,
  108.       'EmailObject': instance.email_object,
  109.       'Message': instance.message,
  110.     };
  111.   }
  112. }
  113.  
  114. class DatiFormStore {
  115.   var email,
  116.       message,
  117.       problemaDaSegnalare,
  118.       productId,
  119.       storeID,
  120.       email_object = '';
  121.  
  122.   DatiFormStore() {
  123.     email = '';
  124.     email_object = '';
  125.     productId = '';
  126.     storeID = '';
  127.   }
  128.  
  129.   Map<String, dynamic> itemToJson(DatiFormStore instance) {
  130.     return <String, dynamic>{
  131.       'ProductID': instance.productId,
  132.       'StoreID': instance.storeID,
  133.       'EmailObject': instance.email_object,
  134.       'Message': instance.message,
  135.       'ProblemaDaSegnalare': instance.problemaDaSegnalare
  136.     };
  137.   }
  138. }
  139.  
  140. class DatiFormProduct {
  141.   var email, message, problemaDaSegnalare, productId, email_object = '';
  142.  
  143.   DatiFormProduct() {
  144.     email = '';
  145.     email_object = '';
  146.     productId = '';
  147.   }
  148.  
  149.   Map<String, dynamic> itemToJson(DatiFormProduct instance) {
  150.     return <String, dynamic>{
  151.       'ProductID': instance.productId,
  152.       'EmailObject': instance.email_object,
  153.       'Message': instance.message,
  154.       'ProblemaDaSegnalare': instance.problemaDaSegnalare
  155.     };
  156.   }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement