Ejemplo n.º 1
0
        public async Task <IActionResult> GetOne(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new UserQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            return(new OkObjectResult(result));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetOne(int id)
        {
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new UserQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                return(new OkObjectResult(result));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteOne(int id)
        {
            await Db.Connection.OpenAsync();

            var query  = new UserQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }
            result.Deleted = true;
            await PutOne(id, result);

            return(new OkResult());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PutOne(int id, [FromBody] User body)
        {
            using (var db = new AppDb())
            {
                await db.Connection.OpenAsync();

                var query  = new UserQuery(db);
                var result = await query.FindOneAsync(id);

                if (result == null)
                {
                    return(new NotFoundResult());
                }
                result.name = body.name;
                await result.UpdateAsync();

                return(new OkObjectResult(result));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutOne(int id, [FromBody] Users body)
        {
            await Db.Connection.OpenAsync();

            var query  = new UserQuery(Db);
            var result = await query.FindOneAsync(id);

            if (result is null)
            {
                return(new NotFoundResult());
            }

            result.Name        = body.Name;
            result.Password    = body.Password;
            result.Age         = body.Age;
            result.DateCreated = body.DateCreated;
            result.Deleted     = body.Deleted;
            await result.UpdateAsync(id);

            return(new OkObjectResult(result));
        }