Код: Выделить всё
using Google.Protobuf;
using Microsoft.Graph;
using Microsoft.Identity.Client;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json.Linq;
using SunApproverFlowsServer.Server.Data;
using SunApproverFlowsServer.Server.Models;
using SunApproverFlowsServer.Server.Services.Interfaces;
using System.Data;
using System.Text.Json;
using System.Xml;
using System.Xml.Linq;
namespace SunApproverFlowsServer.Server.Services.TaskMenagerService
{
public class UserLookup
{
public int LookupId { get; set; }
public string LookupValue { get; set; }
public string Email { get; set; }
}
public class TaskManagerService : ITaskManager
{
private readonly IConfiguration Configuration;
private readonly DataContext _context;
public TaskManagerService(IConfiguration configuration, DataContext context)
{
Configuration = configuration;
_context = context;
}
public async Task AddTaskAsync(ParseXMLDateModel? parseXMLDate)
{
int workflowId = _context.SunApproversWorkflows.FirstOrDefault(el => el.ListGuid == parseXMLDate.ListId).WorkflowId;
string siteName = Configuration["SharepointSiteInf:SiteName"];
string clientId = Configuration["AuthenticationData:ClientId"];
string tenantId = Configuration["AuthenticationData:TenantId"];
string clientSecret = Configuration["AuthenticationData:ClientSecret"];
string taskListName = Configuration["ListsTitles:TaskListName"];
string linksListName = Configuration["ListsTitles:LinksListName"];
try
{
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
GraphServiceClient _graphClient = new GraphServiceClient(clientSecretCredential);
var itemsFilds = await _graphClient.Sites[siteName].Lists[linksListName].Items.Request()
.Expand("Fields")
.GetAsync();
foreach (var item in itemsFilds)
{
var workflowLookupId = item.Fields.AdditionalData["WorkflowLookupId"].ToString();
if (workflowLookupId != null && Convert.ToInt32(workflowLookupId) == workflowId)
{
//var usersArray = item.Fields.AdditionalData["Users"];
var usersArrayJson = item.Fields.AdditionalData["Users"].ToString();
var usersArray = JsonSerializer.Deserialize(usersArrayJson);
var lookupIds = usersArray.Select(user => user.LookupId.ToString()).ToArray();
var requestBody = new ListItem
{
Fields = new FieldValueSet
{
AdditionalData = new Dictionary
{
{
"Title", item.Fields.AdditionalData["StatusLookupId"] ?? "Not specified"
},
{
"AssignedTo@odata.type", "Collection(Edm.String)"
},
{
"AssignedTo", lookupIds
},
{
"Body", parseXMLDate.Description ?? "Not specified"
}
}
}
};
var result = await _graphClient.Sites[siteName].Lists[taskListName].Items.Request().AddAsync(requestBody);
}
}
return $" \nIn task list \"{taskListName}\" added new item.\n";
}
catch (Exception e)
{
return e.Message;
}
}
}
}
[img]https://i.sstatic. net/gw6ZlcdI.png[/img]
В проекте используется Microsoft Graph версии 4.54.0. Буду рад получить информацию как по этой, так и по более новым версиям. Заранее спасибо за ответ.
Подробнее здесь: https://stackoverflow.com/questions/785 ... soft-graph
Мобильная версия