Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] TechnologyRequest request)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                return(BadRequest(new { error = "Technology name must be not empty" }));
            }
            var newTechnology = new Technology
            {
                Id          = Guid.NewGuid().ToString(),
                Name        = request.Name,
                Description = request.Description
            };

            var created = await _technologyService.CreateTechnologyAsync(newTechnology);

            if (!created)
            {
                return(BadRequest(new { error = "Unable to create technology" }));
            }

            var locationUri = HttpContext.GetLocationURI(Routes.Technology.Get).Replace("{technologyId}", newTechnology.Id);

            return(Created(locationUri, _mapper.Map <TechnologyResponse>(newTechnology)));
        }