Coder Social home page Coder Social logo

Comments (3)

Rudomitori avatar Rudomitori commented on September 28, 2024 2

Some minimal API samples from the Microsoft's documentation

app.MapPost("/todoitems", async (Todo todo, TodoDb db) =>
{
    db.Todos.Add(todo);
    await db.SaveChangesAsync();

    return Results.Created($"/todoitems/{todo.Id}", todo);
});

app.MapPut("/todoitems/{id}", async (int id, Todo inputTodo, TodoDb db) =>
{
    var todo = await db.Todos.FindAsync(id);

    if (todo is null) return Results.NotFound();

    todo.Name = inputTodo.Name;
    todo.IsComplete = inputTodo.IsComplete;

    await db.SaveChangesAsync();

    return Results.NoContent();
});

app.MapDelete("/todoitems/{id}", async (int id, TodoDb db) =>
{
    if (await db.Todos.FindAsync(id) is Todo todo)
    {
        db.Todos.Remove(todo);
        await db.SaveChangesAsync();
        return Results.NoContent();
    }

    return Results.NotFound();
});

from csharpier.

belav avatar belav commented on September 28, 2024

FWIW prettier appears to avoid breaking arguments when one of them is a lambda. I haven't looked into the code to see if this was intenional or not, but I assume that it was.

Prettier output

await SessionManager.Session(cancellationToken, async (context) => {
  var records = await context.DbContext.Entity.AsNoTracking()
    .Where(
      context.DbContext.PredicateFor(criteria).TranslatedBy(MkEntityPredicates),
    )
    .ToListAsync(context.CancellationToken);

  var entities = await MarshalEntities(records);

  return entities.ToImmutableDictionary((e) => e.Id.Value);
});

from csharpier.

jcracknell avatar jcracknell commented on September 28, 2024

Sorry, to be clear this is using prettier with prettier-plugin-csharp?

I'd be fine with wrapping arguments when they contain a lambda which is not block-bodied, e.g.

var exception = Assert.Throws<Exception>(
    () => my.Incredibly.Long.Ass.Lambda.Expression
);

but blocks should probably be treated as blocks regardless of where they appear:

var exception = Assert.Throws<Exception>(() =>
{
    throw new Exception();
});

from csharpier.

Related Issues (20)

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.