DocSpace-buildtools/common/ASC.Api.Core/Routing/FormatRoute.cs

59 lines
2.0 KiB
C#
Raw Normal View History

2019-06-25 07:34:27 +00:00
using System.Collections.Generic;
2019-06-25 11:17:04 +00:00
using System.Net.Http;
2020-03-16 08:25:39 +00:00
2019-06-25 07:34:27 +00:00
using Microsoft.AspNetCore.Mvc.Routing;
2019-05-27 12:49:48 +00:00
namespace ASC.Web.Api.Routing
{
2019-06-25 07:34:27 +00:00
public abstract class CustomHttpMethodAttribute : HttpMethodAttribute
2019-05-27 12:49:48 +00:00
{
2019-06-25 07:34:27 +00:00
public bool Check { get; set; }
2020-03-16 08:25:39 +00:00
public bool DisableFormat { get; set; }
2019-06-25 07:34:27 +00:00
2019-06-25 11:17:04 +00:00
public CustomHttpMethodAttribute(string method, string template = null, bool check = true, int order = 1)
: base(new List<string>() { method }, $"[controller]{(template != null ? $"/{template}" : "")}")
2019-06-13 15:01:29 +00:00
{
2019-06-25 07:34:27 +00:00
Check = check;
2019-06-25 11:17:04 +00:00
Order = order;
2019-06-13 15:01:29 +00:00
}
2019-06-25 07:34:27 +00:00
}
public class ReadAttribute : CustomHttpMethodAttribute
{
2019-06-25 11:17:04 +00:00
public ReadAttribute(bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
this(null, check, order)
{ }
2019-06-25 11:17:04 +00:00
2019-06-25 10:46:10 +00:00
public ReadAttribute(string template, bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
base(HttpMethod.Get.Method, template, check, order)
{ }
2019-06-14 08:15:28 +00:00
}
2019-06-25 07:34:27 +00:00
public class CreateAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 11:17:04 +00:00
public CreateAttribute(bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
this(null, check, order)
{ }
2019-06-25 10:46:10 +00:00
public CreateAttribute(string template, bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
base(HttpMethod.Post.Method, template, check, order)
{ }
}
2019-06-25 07:34:27 +00:00
public class UpdateAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 11:17:04 +00:00
public UpdateAttribute(bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
this(null, check, order)
{ }
2019-06-25 10:46:10 +00:00
public UpdateAttribute(string template, bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
base(HttpMethod.Put.Method, template, check, order)
{ }
2019-06-14 08:15:28 +00:00
}
2019-06-25 07:34:27 +00:00
public class DeleteAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 11:17:04 +00:00
public DeleteAttribute(bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
this(null, check, order)
{ }
2019-06-25 10:46:10 +00:00
public DeleteAttribute(string template, bool check = true, int order = 1) :
2019-08-15 12:04:42 +00:00
base(HttpMethod.Delete.Method, template, check, order)
{ }
2019-05-27 12:49:48 +00:00
}
}