Skip to content

Instantly share code, notes, and snippets.

View alincak's full-sized avatar
🏠
Working from home

alincak

🏠
Working from home
View GitHub Profile
@alincak
alincak / SendMessage.cs
Created July 4, 2020 10:02
Microsoft Graph API SendMessage
public async Task<(bool success, string message)> SendMessage(string messageId)
{
try
{
await graphClient.Me.Messages[messageId]
.Send()
.Request()
.PostAsync();
return (true, null);
@alincak
alincak / MessageCreateUploadSession.cs
Created July 4, 2020 09:44
Microsoft Graph API MessageCreateUploadSession
private async Task<bool> MessageCreateUploadSession(string messageId, string fileName, byte[] bytes)
{
try
{
using (Stream stream = new MemoryStream(bytes))
{
var attachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = fileName,
@alincak
alincak / AddAttachments.cs
Created July 4, 2020 09:36
Microsoft Graph API AddAttachments
var attachment = new FileAttachment
{
Name = fileName,
ContentBytes = bytes
};
await graphClient.Me.Messages[messageId].Attachments
.Request()
.AddAsync(attachment).ConfigureAwait(false);
@alincak
alincak / DeleteMessage.cs
Created July 4, 2020 09:25
Microsoft Graph API Delete Message
private async Task DeleteMessage(string messageId)
{
try
{
await graphClient.Me.Messages[messageId]
.Request()
.DeleteAsync();
}
catch (Exception ex)
{
@alincak
alincak / CreateDraftMessage.cs
Last active July 4, 2020 09:34
Microsoft Graph API CreateDraftMessage
public async Task<string> CreateDraftMessage(string messageId, IList<string> toEmails, string subject, string body)
{
if (toEmails == null || !toEmails.Any() || string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(body))
{
return null;
}
var message = new Message
{
Subject = subject,
@alincak
alincak / GraphServiceClient.cs
Last active July 4, 2020 09:35
Microsoft Graph API GraphServiceClient
private GraphServiceClient CreateGraphClientAsync(string token)
{
return new GraphServiceClient(
new DelegateAuthenticationProvider(
(request) =>
{
if (!string.IsNullOrEmpty(token))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
[HttpGet]
[SwaggerResponse(System.Net.HttpStatusCode.NotFound, "Customer not found or no access", typeof(ErrorMessageVo))]
public CustomerGetResponseVo Get(int id)
{
return new CustomerGetResponseVo();
}
public class ApplyDocumentFilter : IDocumentFilter
{
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
swaggerDoc.info = GetInfo();
swaggerDoc.securityDefinitions = GetSecurityDefinitions();
var tagGroups = GetTagGroups();
var tagsDescriptions = GetTagsDescription();
public class ApplyOperationFilter : IOperationFilter
{
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null) return;
InitSetContentTypeJson(operation);
InitSchemaOneOf(operation);
InitFromUriParameters(operation, apiDescription);
}
@alincak
alincak / ApplySchemaFilter.cs
Created December 7, 2019 14:17
Swagger ApplySchemaFilter
public class ApplySchemaFilter : ISchemaFilter
{
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
{
if (schema?.properties == null || type == null)
return;
var excludedProperties = type.GetProperties()
.Where(t =>
t.GetCustomAttribute<SwaggerExcludeAttribute>()