private OpenAPIRonnies.Domain.Ronny CreateOrUpdateRonnyToDbRonny(CreateOrUpdateRonny createOrUpdateRonny) { return(new Domain.Ronny { Name = createOrUpdateRonny.Name, Price = createOrUpdateRonny.Price }); }
public async Task <SwaggerResponse <Ronny> > CreateRonnyAsync(CreateOrUpdateRonny body) { var ronny = CreateOrUpdateRonnyToDbRonny(body); ronny.Created = DateTimeOffset.UtcNow; ronny.Id = Guid.NewGuid(); await _ronnyContext.Ronnies.AddAsync(ronny); await _ronnyContext.SaveChangesAsync(); return(new SwaggerResponse <Ronny>(HttpStatusCode.Created, DbRonnyToReadRonny(ronny))); }
public async Task <SwaggerResponse <Ronny> > UpdateRonnyAsync(CreateOrUpdateRonny body, string ronnyId) { if (Guid.TryParse(ronnyId, out var id)) { var existingRonny = await _ronnyContext.Ronnies.FindAsync(id); if (existingRonny != null) { existingRonny.Name = body.Name; existingRonny.Price = body.Price; await _ronnyContext.SaveChangesAsync(); return(new SwaggerResponse <Ronny>(HttpStatusCode.Accepted, DbRonnyToReadRonny(existingRonny))); } else { return(new SwaggerResponse <Ronny>(HttpStatusCode.NotFound)); } } else { return(SwaggerResponse <Ronny> .BadRequest("Invalid PK format")); } }