添加采购入库单接口
统一
This commit is contained in:
@@ -6,12 +6,62 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
|
||||
namespace NX.ERP.WebAPi
|
||||
{
|
||||
|
||||
public class ExceptionFilter : System.Web.Http.Filters.IExceptionFilter
|
||||
{
|
||||
public bool AllowMultiple => throw new NotImplementedException();
|
||||
|
||||
public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
|
||||
{
|
||||
var ex = actionExecutedContext.Exception;
|
||||
actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage();
|
||||
|
||||
actionExecutedContext.Response.Content = new System.Net.Http.ObjectContent(typeof(ResultModel<string>),
|
||||
new ResultModel<string> { ErrCode = 500, ErrMsg = ex.Message, Data = null },
|
||||
new JsonMediaTypeFormatter());
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
|
||||
public class ApiResultAttribute : System.Web.Http.Filters.ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
|
||||
{
|
||||
base.OnActionExecuted(actionExecutedContext);
|
||||
if (actionExecutedContext.Exception == null)
|
||||
{
|
||||
ResultModel<object> result = new ResultModel<object>();
|
||||
// 取得由 API 返回的状态代码
|
||||
result.ErrCode = 0;
|
||||
// 取得由 API 返回的资料
|
||||
result.Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync<object>().Result;
|
||||
|
||||
//请求是否成功
|
||||
// result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode;
|
||||
//结果转为自定义消息格式
|
||||
HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(result, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings)) };
|
||||
// 重新封装回传格式
|
||||
actionExecutedContext.Response = httpResponseMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class JsonContentNegotiator : IContentNegotiator
|
||||
{
|
||||
|
||||
private readonly JsonMediaTypeFormatter _jsonFormatter;
|
||||
|
||||
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
|
||||
@@ -29,6 +79,10 @@ namespace NX.ERP.WebAPi
|
||||
{
|
||||
public static void Register(HttpConfiguration config)
|
||||
{
|
||||
//System.Web.Http.Filters.IExceptionFilter
|
||||
config.Filters.Add(new ExceptionFilter());
|
||||
config.Filters.Add(new ApiResultAttribute());
|
||||
Console.WriteLine(config.Filters.Count);
|
||||
// Web API 配置和服务
|
||||
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
@@ -36,12 +90,13 @@ namespace NX.ERP.WebAPi
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
//小驼峰命名法
|
||||
ContractResolver = new DefaultContractResolver() {
|
||||
ContractResolver = new DefaultContractResolver()
|
||||
{
|
||||
|
||||
NamingStrategy = new SnakeCaseNamingStrategy()
|
||||
}
|
||||
//格式化日期时间
|
||||
|
||||
|
||||
//空值处理
|
||||
//NullValueHandling = NullValueHandling.Ignore
|
||||
|
||||
@@ -50,7 +105,7 @@ namespace NX.ERP.WebAPi
|
||||
|
||||
// Web API 路由
|
||||
config.MapHttpAttributeRoutes();
|
||||
|
||||
|
||||
config.Routes.MapHttpRoute(
|
||||
name: "DefaultApi",
|
||||
routeTemplate: "api/{controller}/{action}/{code}",
|
||||
|
||||
18
NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs
Normal file
18
NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace NX.ERP.WebAPi.Controllers.Store
|
||||
{
|
||||
public class PuStoreInController : ApiController
|
||||
{
|
||||
[HttpPost]
|
||||
public string AddVoucher([FromBody] Model.Store.PuStoreIn storeIn)
|
||||
{
|
||||
var dal = new NX.ERP.U8.Store.PuStoreInDAL();
|
||||
return dal.AddVocher(storeIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
<UseGlobalApplicationHostFile />
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -34,6 +35,8 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -43,20 +46,26 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="ADODB, Version=2.6.0.0, Culture=neutral, PublicKeyToken=79a4e7ad54eeabca">
|
||||
<HintPath>E:\U8SOFT\Interop\ADODB.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Abstractions" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Web.Routing" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Configuration" />
|
||||
@@ -108,6 +117,7 @@
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="WebGrease">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
|
||||
@@ -137,10 +147,12 @@
|
||||
<Compile Include="Controllers\Base\SupplierController.cs" />
|
||||
<Compile Include="Controllers\Base\UnitController.cs" />
|
||||
<Compile Include="Controllers\Base\WarehouseController.cs" />
|
||||
<Compile Include="Controllers\Store\PuStoreInController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResultModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="favicon.ico" />
|
||||
@@ -155,7 +167,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
<Folder Include="Controllers\Store\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
14
NX.ERP.WebAPi/ResultModel.cs
Normal file
14
NX.ERP.WebAPi/ResultModel.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace NX.ERP.WebAPi
|
||||
{
|
||||
public class ResultModel<T>
|
||||
{
|
||||
public int ErrCode { get; set; }
|
||||
public string ErrMsg { get; set; } = "";
|
||||
public T Data { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user