Code Monkey home page Code Monkey logo

netutilitykit.nuget's Introduction

NetUtilityKit.LibraryNuget

MIT License

It allows you to develop your projects quickly. It contains many supporting structures. Contact us if you want to support.

Install

 dotnet add package NetUtilityKit --version 1.0.1

Package Included

ResponseModel:

It ensures that the controller is clean and legible.
It allows you to give a stronger and different response. Different Overloads are available.
There is no need to do if else in the controller. You can manage this situation from a different layer.
If you don't want to repeat yourself, you can manage the controller part with a base class.
A simple example is presented.

ExpressionParser:

Converting the filtering expression you receive as a string by the client to the expression type.
In this way, you can quickly perform powerful filtering operations with a single method.
You may need to set limits on filters for security.

Use ResponseModel

Example- Service
    public async Task<ResponseModel<bool>> CreateItemAsync(CreateItemDto createItemDto, CancellationToken cancellationToken)
    {
        try
        {
            await AddItemAsync(createItemDto, cancellationToken);

            return ResponseModel<bool>.SuccessResponse(true, 201);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex.Message);

            return ResponseModel<bool>.ErrorResponse($"{ex.Message}", 500);
        }
    }

Example- Controller

  [HttpPost]
    public async Task<IActionResult> Create(CreateItemDto createItemDto, CancellationToken cancellationToken)
    {
        var response = await _itemService.CreateItemAsync(createItemDto, cancellationToken);

        return new ObjectResult(response)
        {
            StatusCode = response.StatusCode
        };
    }

Use ExpressionParser

Example - Request Query And Body

public sealed record GetAllFilterCustomerQuery(
  string Expression
);

Example- Service

  public async Task<List<Customer>> GetAllFilter(GetAllFilterCustomerQuery request)
  {
     
      var expression = ExpressionParser.ParseExpression<Customer>(request.Expression);

      var query = _queryRepository.GetAll().Where(expression).Include(p => p.CustomerType).ToListAsync();    

      return result;

  }

Example - Request
{
  "expression": "x=> x.IsActive == true"
}

By Abdullah Balikci - berjcode

netutilitykit.nuget's People

Contributors

berjcode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.