public async Task <SaveActionsResponse> UpdateAsync(int id, UpdateActionsResource resource)
        {
            var Actions         = _mapper.Map <UpdateActionsResource, ActionsModels>(resource);
            var existingActions = await _ActionsRepository.ReadOneAsync(id);

            if (existingActions == null)
            {
                return(new SaveActionsResponse("Category not found."));
            }

            existingActions.action         = Actions.action;
            existingActions.update_user_id = Actions.update_user_id;
            existingActions.update_time    = Actions.update_time;

            try
            {
                await _ActionsRepository.UpdateAsync(existingActions);

                return(new SaveActionsResponse(existingActions));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveActionsResponse($"An error occurred when updating the category: {ex.Message}"));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UpdateAsync(int id, [FromBody] UpdateActionsResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var result = await _ActionsService.UpdateAsync(id, resource);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(new { msg = "更新成功!" }));
        }