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

67 lines
2.5 KiB
C#
Raw Normal View History

2019-06-25 07:34:27 +00:00
using System.Collections.Generic;
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; }
public CustomHttpMethodAttribute(string method, string template, bool check = true)
: base(new List<string>() { method }, template)
2019-06-13 15:01:29 +00:00
{
2019-06-25 07:34:27 +00:00
Check = check;
2019-06-13 15:01:29 +00:00
}
2019-06-25 07:34:27 +00:00
}
public class ReadAttribute : CustomHttpMethodAttribute
{
public ReadAttribute(bool format = true, bool check = true) :
base("GET", $"[controller]{(format ? ".{format}" : "")}", check)
{
}
public ReadAttribute(string template, bool format = true, int order = 1, bool check = true) :
base("GET", $"[controller]/{template}{(!format ? "": (template.EndsWith("}") ? ".{format?}" : ".{format}"))}", check)
2019-05-27 12:49:48 +00:00
{
2019-06-14 08:15:28 +00:00
Order = order;
}
}
2019-06-25 07:34:27 +00:00
public class CreateAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 07:34:27 +00:00
public CreateAttribute(bool format = true, bool check = true) :
base("POST", $"[controller]{(format ? ".{format}" : "")}", check)
2019-06-14 08:15:28 +00:00
{
}
2019-06-25 07:34:27 +00:00
public CreateAttribute(string template, bool format = true, int order = 1, bool check = true) :
base("POST", $"[controller]/{template}{(!format ? "": (template.EndsWith("}") ? ".{format?}" : ".{format}"))}", check)
2019-06-14 08:15:28 +00:00
{
Order = order;
}
}
2019-06-25 07:34:27 +00:00
public class UpdateAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 07:34:27 +00:00
public UpdateAttribute(bool format = true, bool check = true) :
base("PUT", $"[controller]{(format ? ".{format}" : "")}", check)
2019-06-14 08:15:28 +00:00
{
}
2019-06-25 07:34:27 +00:00
public UpdateAttribute(string template, bool format = true, int order = 1, bool check = true) :
base("PUT" ,$"[controller]/{template}{(!format ? "": (template.EndsWith("}") ? ".{format?}" : ".{format}"))}", check)
2019-06-14 08:15:28 +00:00
{
Order = order;
}
}
2019-06-25 07:34:27 +00:00
public class DeleteAttribute : CustomHttpMethodAttribute
2019-06-14 08:15:28 +00:00
{
2019-06-25 07:34:27 +00:00
public DeleteAttribute(bool format = true, bool check = true) :
base("DELETE", $"[controller]{(format ? ".{format}" : "")}", check)
2019-06-14 08:15:28 +00:00
{
}
2019-06-25 07:34:27 +00:00
public DeleteAttribute(string template, bool format = true, int order = 1, bool check = true) :
base("DELETE", $"[controller]/{template}{(!format ? "": (template.EndsWith("}") ? ".{format?}" : ".{format}"))}", check)
2019-06-14 08:15:28 +00:00
{
Order = order;
2019-05-27 12:49:48 +00:00
}
}
}