Skip to content

Instantly share code, notes, and snippets.

@mortezadalil
Created December 8, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortezadalil/37c63ee964451ddf4d81b23f1b50d157 to your computer and use it in GitHub Desktop.
Save mortezadalil/37c63ee964451ddf4d81b23f1b50d157 to your computer and use it in GitHub Desktop.
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