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)); }