public async Task <IActionResult> UpdatePartAsync(UpdatePartRequest request) { var mappedPart = Mapper.Map <UpdatePartRequest, Part>(request); var partType = await GetPartTypeAsync(request.PartTypeId); if (partType == null) { return(BadRequest($"Invalid Part Type: {request.PartTypeId}")); } mappedPart.PartTypeId = partType.PartTypeId; mappedPart.MountingTypeId = GetMountingTypeId(request.MountingTypeId); if (mappedPart.MountingTypeId <= 0) { return(BadRequest($"Invalid Mounting Type: {request.MountingTypeId}")); } mappedPart.PartId = request.PartId; mappedPart.Keywords = request.Keywords?.Split(new string[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries); var part = await _partService.UpdatePartAsync(mappedPart); var partResponse = Mapper.Map <Part, PartResponse>(part); partResponse.PartType = partType.Name; partResponse.Keywords = string.Join(" ", part.Keywords ?? new List <string>()); return(Ok(partResponse)); }
public async Task <IActionResult> UpdatePartAsync(UpdatePartRequest request) { var partType = await _partService.GetOrCreatePartTypeAsync(new PartType { Name = request.PartType }); var mappedPart = Mapper.Map <UpdatePartRequest, Part>(request); mappedPart.PartId = request.PartId; mappedPart.Keywords = request.Keywords?.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); mappedPart.PartTypeId = partType.PartTypeId; mappedPart.MountingTypeId = (int)Enum.Parse <MountingType>(request.MountingType.Replace(" ", ""), true); var part = await _partService.UpdatePartAsync(mappedPart); var partResponse = Mapper.Map <Part, PartResponse>(part); partResponse.PartType = partType.Name; return(Ok(partResponse)); }