Beispiel #1
0
        public async Task <SwaggerResponse> DeleteRonnyAsync(string ronnyId)
        {
            if (Guid.TryParse(ronnyId, out var id))
            {
                var ronny = await _ronnyContext.Ronnies.FindAsync(id);

                _ronnyContext.Ronnies.Remove(ronny);
                await _ronnyContext.SaveChangesAsync();

                return(new SwaggerResponse(HttpStatusCode.OK));
            }
            else
            {
                return(SwaggerResponse <Ronny> .BadRequest("Invalid PK format"));
            }
        }
Beispiel #2
0
        public async Task <SwaggerResponse <Ronny> > GetRonnyAsync(string ronnyId)
        {
            if (Guid.TryParse(ronnyId, out var id))
            {
                var ronny = await _ronnyContext.Ronnies.FindAsync(id);

                if (ronny != null)
                {
                    return(new SwaggerResponse <Ronny>(HttpStatusCode.OK, DbRonnyToReadRonny(ronny)));
                }
                else
                {
                    return(new SwaggerResponse <Ronny>(HttpStatusCode.NotFound));
                }
            }
            else
            {
                return(SwaggerResponse <Ronny> .BadRequest("Invalid PK format"));
            }
        }
Beispiel #3
0
        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"));
            }
        }