public static void AddAccusseDeLecture(string webUrl, int docID, string docName, User lecteur, string taxLabel = null, string termGuid = null) { using (ClientContext ctx = SPConnection.GetSPOLContext(webUrl)) { List itemList = ctx.Web.Lists.GetByTitle("Accusés de lecture"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem itemtoADD = itemList.AddItem(itemCreateInfo); itemtoADD["Title"] = docName; FieldUserValue usrValue = new FieldUserValue(); usrValue.LookupId = lecteur.Id;; itemtoADD["Lecteur"] = usrValue; if (!string.IsNullOrEmpty(taxLabel)) { var termValue = new TaxonomyFieldValue(); termValue.Label = taxLabel; termValue.TermGuid = termGuid; termValue.WssId = -1; itemtoADD["UF_x0020_du_x0020_lecteur"] = termValue; } FieldLookupValue val = new FieldLookupValue(); val.LookupId = docID; itemtoADD["Document"] = val; itemtoADD["Document_x0020_lu"] = false; itemtoADD["Commentaires_x0020__x0028_inform"] = ""; itemtoADD.Update(); ctx.ExecuteQuery(); } }
public static void SendEmail(string webUrl, FieldUserValue[] users, string Subject, int index, FieldUserValue[] userReceived, ListItem item) { using (ClientContext ctx = SPConnection.GetSPOLContext(webUrl)) { foreach (FieldUserValue user in users) { bool notcontain = true; if (userReceived != null) { foreach (FieldUserValue recuser in userReceived) { if (user.Email == recuser.Email) { notcontain = false; } } } if (notcontain) { List <string> usersEmail = new List <string> { }; usersEmail.Add(user.Email.ToString()); string body = ""; if (index == 4) { body = EmailBody(index, item, user.Email.ToString(), users); } else { body = EmailBody(index, item, user.Email.ToString()); } try { ///jke risk of dispose // using (ctx) { var emailProperties = new EmailProperties(); //Email of authenticated external user emailProperties.To = usersEmail; emailProperties.From = "*****@*****.**"; emailProperties.Body = body; emailProperties.Subject = Subject; //emailProperties.CC = cc; Utility.SendEmail(ctx, emailProperties); ctx.ExecuteQuery(); } } catch (Exception ex) { } } } } }
public static void getStatus(string webUrl, int Id, string listName, ILogger log) { using (ClientContext ctx = SPConnection.GetSPOLContext(webUrl)) { try { string envoi = ""; string status = ""; string Cycle = ""; FieldUserValue[] emptyuser = null; List <String> CibleIDs = new List <string>(); List itemList = ctx.Web.Lists.GetByTitle(listName); ListItem item = itemList.GetItemById(Id); ctx.Load(item); ctx.ExecuteQuery(); status = item["Etat"].ToString(); envoi = item["Envoyer_x0020_le_x0020_document_x0020_pour_x0020_v_x00e9_rification_x002f_validation"].ToString(); Cycle = item["Cycle_x0020_de_x0020_vie"].ToString(); string OldStatus = item["AncienEtat"] != null ? item["AncienEtat"].ToString() : string.Empty; log.LogInformation("Old Status " + OldStatus); log.LogInformation("Status " + status); if (!string.Equals(status, OldStatus) && item["Cat_x00e9_gories"] != null) { if (item["R_x00e9_f_x00e9_rence"] == null) { TaxonomyFieldValueCollection tax = item["Cat_x00e9_gories"] as TaxonomyFieldValueCollection; TaxonomyFieldValue typeDoc = item["Type_x0020_de_x0020_document"] as TaxonomyFieldValue; item["R_x00e9_f_x00e9_rence"] = SetReference(ctx, tax, typeDoc, item.Id); } log.LogInformation("Enterin Update"); item["AncienEtat"] = status; // item.SystemUpdate(); ResetBreakRoleInheritance(ctx, item); switch (status) { case "Brouillon": SendEmail(webUrl, (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], "GED - Un document à été créé", 1, (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_R_x00e9_dacteur_x0028_s_x0029_"], item); SPPermissionAuteur(ctx, item, "modify", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "modify", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); UpdateReceivedEmail(item, "Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_R_x00e9_dacteur_x0028_s_x0029_", (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_R_x00e9_dacteur_x0028_s_x0029_"], (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"]); // UpdateReceivedEmail(ctx, "Redacteur", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], listName, Id); if (envoi == "True" && Cycle.Contains("Rédaction/Validation")) { item["Etat"] = "En attente de validation"; // item.Update(); } if (envoi == "True" && !Cycle.Contains("Rédaction/Validation")) { item["Etat"] = "En attente de vérification"; //item.Update(); } // item.SystemUpdate(); break; case "En attente de vérification": SPPermissionAuteur(ctx, item, "read", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); SPPermission(ctx, item, "modify", (FieldUserValue[])item["V_x00e9_rificateurs"], false); SendEmail(webUrl, (FieldUserValue[])item["V_x00e9_rificateurs"], "GED - Demande de vérification d'un document", 2, (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_V_x00e9_rificateur_x0028_s_x0029_"], item); UpdateReceivedEmail(item, "Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_V_x00e9_rificateur_x0028_s_x0029_", (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_au_x0028_x_x0029__x0020_V_x00e9_rificateur_x0028_s_x0029_"], (FieldUserValue[])item["V_x00e9_rificateurs"]); // UpdateReceivedEmail(ctx, "Verificateur", (FieldUserValue[])item["V_x00e9_rificateurs"], listName, Id); break; case "En attente de validation": SPPermissionAuteur(ctx, item, "read", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["V_x00e9_rificateurs"], false); SPPermission(ctx, item, "modify", (FieldUserValue[])item["Validateur_x0028_s_x0029_"], false); SendEmail(webUrl, (FieldUserValue[])item["Validateur_x0028_s_x0029_"], "GED - Un document est en attente de validation", 6, (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_aux_x0020_V_x00e9_rificateur_x0028_s_x0029_"], item); UpdateReceivedEmail(item, "Email_x0020_envoy_x00e9__x0020_aux_x0020_V_x00e9_rificateur_x0028_s_x0029_", (FieldUserValue[])item["Email_x0020_envoy_x00e9__x0020_aux_x0020_V_x00e9_rificateur_x0028_s_x0029_"], (FieldUserValue[])item["Validateur_x0028_s_x0029_"]); // UpdateReceivedEmail(ctx, "Validateur", (FieldUserValue[])item["Validateur_x0028_s_x0029_"], listName, Id); break; case "En attente de publication": SPPermissionAuteur(ctx, item, "read", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["V_x00e9_rificateurs"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Validateur_x0028_s_x0029_"], false); break; case "Publié": SPPermissionAuteur(ctx, item, "read", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["V_x00e9_rificateurs"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Validateur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], false); //Cible individuel info SendEmail(webUrl, (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], "GED - Nouveau document publié", 3, (FieldUserValue[])item["Email_x0020_Cible_x0020_indiv_x0020_info"], item); UpdateReceivedEmail(item, "Email_x0020_Cible_x0020_indiv_x0020_application", (FieldUserValue[])item["Email_x0020_Cible_x0020_indiv_x0020_application"], (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"]); // UpdateReceivedEmail(ctx, "CibleIndvInfo", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], listName, Id); string emailsToSend = string.Empty; //cible individuel application SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], true); SendEmail(webUrl, (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], "GED - Nouveau document publié", 4, (FieldUserValue[])item["Email_x0020_Cible_x0020_indiv_x0020_application"], item); UpdateReceivedEmail(item, "Email_x0020_Cible_x0020_indiv_x0020_info", (FieldUserValue[])item["Email_x0020_Cible_x0020_indiv_x0020_info"], (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"]); // UpdateReceivedEmail(ctx, "Email_x0020_Cible_x0020_indiv_x0020_application"", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], listName, Id); ClientContext ctx1 = SPConnection.GetSPOLContext(webUrl); //cible collective info ApplyCibCollectiveProcess(ctx, ctx1, item, "Email_x0020_Cible_x0020_indiv_x0020_info", "Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information", false); //SendEmail(ctx, (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], "Subject", "from", "body", emptyuser); //cible collective application ApplyCibCollectiveProcess(ctx, ctx1, item, "Email_x0020_Cible_x0020_indiv_x0020_application", "Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application", true); ctx1.Dispose(); //SendEmail(ctx, (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], "Subject", 1, emptyuser,item); break; case "En attente de révision": SPPermissionAuteur(ctx, item, "modify", (FieldUserValue)item["Author"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["R_x00e9_dacteur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["V_x00e9_rificateurs"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Validateur_x0028_s_x0029_"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_information"], false); SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_collective_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], true); SPPermission(ctx, item, "read", (FieldUserValue[])item["Cible_x0028_s_x0029__x0020_individuelle_x0028_s_x0029__x0020_de_x0020_la_x0020_diffusion_x0020_pour_x0020_application"], true); SendEmail(webUrl, (FieldUserValue[])item["Author"], "GED - Document en attente de révision", 5, emptyuser, item); if (item["Passer_x0020_en_x0020_publi_x00e9_"].ToString() == "Yes") { item["Etat"] = "Publié"; // UpdateStatus(ctx, listName, Id); } break; } item.SystemUpdate(); ctx.ExecuteQuery(); } } catch (Exception ex) { log.LogInformation(ex.ToString()); throw ex; } } }