Skip to content

Commit

Permalink
Merge branch 'dhg' into dev/yatou
Browse files Browse the repository at this point in the history
  • Loading branch information
KawhiWei committed Jun 17, 2021
2 parents 8448123 + 94faf42 commit 8a730f8
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
95 changes: 95 additions & 0 deletions src/Destiny.Core.Flow.AspNetCore/AjaxResultOfModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using DestinyCore.AspNetCore;
using DestinyCore.Enums;
using DestinyCore.Extensions;
using DestinyCore.Filter;
using DestinyCore.Helpers;
using DestinyCore.Ui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Destiny.Core.Flow.AspNetCore
{
public class AjaxResult<TData> : ResultBase<TData>, IHasResultType<AjaxResultType>
{
public AjaxResultType Type
{
get;
set;
}

public AjaxResult()
{
}

public AjaxResult(AjaxResultType type = AjaxResultType.Success)
: this("", default(TData), type)
{
}

public AjaxResult(string message, AjaxResultType type = AjaxResultType.Success,TData data= default(TData))
: this(message, data, type)
{
}

public AjaxResult(AjaxResultType type = AjaxResultType.Success, TData data= default(TData))
: this("", data, type)
{
}

public AjaxResult(string message, TData data, AjaxResultType type)
{
Message = message;
Data = data;
Type = type;
Success = Succeeded();
}

public AjaxResult(string message, bool success, TData data, AjaxResultType type)
{
Message = message;
Data = data;
Type = type;
Success = success;
}

public bool Succeeded()
{
return Type == AjaxResultType.Success;
}

public bool Error()
{
return Type == AjaxResultType.Error;
}

public object ToObject()
{
return new
{
Data,
Message,
Success,
Type
};
}

/// <summary>
/// 只得到数据
/// </summary>
/// <returns></returns>
public TData GetData()
{
return this.Data;
}

public string ToJson()
{
return ToObject().ToJson();
}
}


}
13 changes: 11 additions & 2 deletions src/Destiny.Core.Flow.AspNetCore/CrudAdminControllerBaseOfModle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
using DestinyCore.AspNetCore;
using DestinyCore.AspNetCore.Api;
using DestinyCore.Entity;
using DestinyCore.Enums;
using DestinyCore.Extensions;
using DestinyCore.Filter;
using DestinyCore.Ui;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
Expand Down Expand Up @@ -80,6 +83,7 @@ public virtual async Task<AjaxResult> CreateAsync([FromBody] IInputDto dto)
public virtual async Task<AjaxResult> LoadDataAsync(TPrimaryKey key) {

return (await CrudServiceAsync.LoadDataByKeyAsync(key)).ToAjaxResult();

}

[Description("异步更新")]
Expand All @@ -101,7 +105,7 @@ public virtual async Task<AjaxResult> DeleteAsync(TPrimaryKey key)

[Description("异步得到分页")]
[HttpPost]
public async Task<PageList<IPagedListDto>> GetPageAsync([FromBody] PageRequest request)
public virtual async Task<PageList<IPagedListDto>> GetPageAsync([FromBody] PageRequest request)
{
return (await CrudServiceAsync.GetPageAsync(request)).ToPageList();

Expand All @@ -113,10 +117,15 @@ public async Task<PageList<IPagedListDto>> GetPageAsync([FromBody] PageRequest r
/// <param name="dto"></param>
[Description("异步创建或更新")]
[HttpPost]
public async Task<AjaxResult> CreateOrUpdateAsync([FromBody] IInputDto dto)
public virtual async Task<AjaxResult> CreateOrUpdateAsync([FromBody] IInputDto dto)
{
return (await CrudServiceAsync.CreateOrUpdateAsync(dto)).ToAjaxResult();
}





}


Expand Down

0 comments on commit 8a730f8

Please sign in to comment.