コード例 #1
0
        public async Task <ActionResult <dynamic> > CreateServer([FromBody] CreateServerResource server)
        {
            var response = await _serverServices.CreateServer(server);

            if (!response.Success)
            {
                return(BadRequest(new ProblemDetails()
                {
                    Type = "https://httpstatuses.com/400",
                    Title = ReasonPhrases.GetReasonPhrase(400),
                    Status = 400,
                    Detail = response.Message
                }));
            }
            return(StatusCode(201, response.Server));
        }
コード例 #2
0
        public async Task <CreateServerResponse> CreateServer(CreateServerResource server)
        {
            try
            {
                var model = _mapper.Map <CreateServerResource, Server>(server);
                model.Id = Guid.NewGuid().ToString();

                await _dataContext.Server.AddAsync(model);

                await _dataContext.SaveChangesAsync();

                return(new CreateServerResponse(_mapper.Map <Server, ServerResource>(model)));
            }
            catch (Exception ex)
            {
                return(new CreateServerResponse(ex.Message));
            }
        }