示例#1
0
        public async Task <IActionResult> UpdateInventoryObjectPartAsync([FromBody] InventoryObjectPartDTO model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                // return 422 - Unprocessable Entity when validation fails
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var part = await _inventoryObjectRepository.GetInventoryObjectPartByIdAsync(model.InventoryObjectPartId);

            if (part == null)
            {
                return(NotFound());
            }

            Mapper.Map(model, part);

            await _inventoryObjectRepository.UpdateInventoryObjectPartAsync(part);

            return(Ok(new { success = true, message = "Add new data success." }));
        }
示例#2
0
        public async Task <IActionResult> AddInventoryObjectPartAsync([FromBody] InventoryObjectPartDTO toAddModel)
        {
            if (toAddModel == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                // return 422 - Unprocessable Entity when validation fails
                return(new UnprocessableEntityObjectResult(ModelState));
            }


            _inventoryObjectRepository.AddInventoryObjectPart(_mapper.Map <InventoryObjectPart>(toAddModel));

            return(Ok(new { success = true, message = "Add new data success." }));
        }