Created
December 8, 2019 10:41
-
-
Save mortezadalil/37c63ee964451ddf4d81b23f1b50d157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
using Cms.Core.Dtos.Generals; | |
using Cms.Core.IUseCases; | |
namespace Cms.Api.Presenters | |
{ | |
public class PostApiPresenter<T> : IOutputPort<GenericResponse<T>> | |
{ | |
public JsonContentResult ContentResult { get; } | |
public PostApiPresenter() | |
{ | |
ContentResult = new JsonContentResult(); | |
} | |
public void Handle(GenericResponse<T> response) | |
{ | |
ContentResult.StatusCode = (int)(response.Success ? HttpStatusCode.OK : HttpStatusCode.BadRequest); | |
ContentResult.Content = ContentResult.Serialize(response.Success ? (object)response.Data : (object)response.Errors); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment