Ejemplo n.º 1
0
        public async Task <Server> Insert(ServerForCreateDto server)
        {
            var user = await context
                       .Users
                       .FirstOrDefaultAsync(u => u.Id == server.OwnerId);

            if (user == null)
            {
                throw new NotFoundException("User not found!");
            }

            var serverToCreate = new Server(
                server.Name,
                user,
                server.IsPrivate);

            context.Servers.Add(serverToCreate);
            await context.SaveChangesAsync();

            return(serverToCreate);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostServer(ServerForCreateDto server)
        {
            var serverCreated = await servers.Insert(server);

            return(CreatedAtAction("GetServer", new { id = serverCreated.Id }, serverCreated));
        }