public async Task <bool> UpdateItemAsync(SnippetModel item) { if (item == null || item.Id == Guid.Empty) { return(false); } var token = await _tokenProvider.GetToken(); var headers = new Dictionary <string, string> { { "Authorization", $"Bearer {token}" } }; var request = new UpdateSnippet(item.Id, item.Name, item.Language, item.Variables, item.Template, item.Code); await _client.PutAsync($"api/Snippet", request, headers); return(true); }
public void UpdateSnippet(UpdateSnippet command, string userName) { var item = _snippetRepository.Get(command.Id); item.Name = command.Name; item.Language = command.Language; item.Template = command.Template; item.Code = command.Code; while (item.Variables.Count > command.Variables.Count) { item.Variables.RemoveAt(item.Variables.Count - 1); } while (item.Variables.Count < command.Variables.Count) { item.Variables.Add(new Variable()); } for (int i = 0; i < item.Variables.Count; i++) { item.Variables[i].Name = command.Variables[i].Name; item.Variables[i].RequestName = command.Variables[i].RequestName; item.Variables[i].DefaultValue = command.Variables[i].DefaultValue; } _snippetRepository.Update(item); _publisher.PublishAsync(new SnippetUpdated( command.Id, command.Name, command.Language, command.Variables, command.Template, command.Code)); }
public ActionResult Update([FromBody] UpdateSnippet command) { _snippetService.UpdateSnippet(command, User.Identity.Name); return(Ok()); }