Ejemplo n.º 1
0
        public async Task <IActionResult> Update([FromRoute] Guid technologyId, [FromBody] TechnologyRequest request)
        {
            var technology = await _technologyService.GetTechnologyByIdAsync(technologyId);

            technology.Name        = request.Name;
            technology.Description = request.Description;

            var updated = await _technologyService.UpdateTechnologyAsync(technology);

            if (updated)
            {
                return(Ok(_mapper.Map <TechnologyResponse>(technology)));
            }

            return(NotFound());
        }
Ejemplo n.º 2
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)));
        }