public void Change(TemplateChangeCommand command) { Add(command, false); Id = command.Id; UpdatedDateUtc = command.UpdatedDateUtc; UpdatedUid = command.UpdatedUid ?? string.Empty; AddEvent(ToAddOrChangeCacheEvent()); }
public async Task <ICommandResult> Handle(TemplateChangeCommand message) { try { ICommandResult result; RTemplate rTemplate = await _templateService.GetById(message.Id); if (rTemplate == null) { result = new CommandResult() { Message = "Template not found", ObjectId = "", Status = CommandResult.StatusEnum.Fail, ResourceName = ResourceKey.Template_NotFound }; return(result); } RTemplateConfig[] rTemplateConfigs = await _templateService.GetTemplateConfigByTemplateId(rTemplate.Id); Template template = new Template(rTemplate, rTemplateConfigs); template.Change(message); await _templateService.Change(template); await _eventSender.Notify(template.Events); result = new CommandResult() { Message = "", ObjectId = template.Id, Status = CommandResult.StatusEnum.Sucess }; return(result); } catch (Exception e) { e.Data["Param"] = message; ICommandResult result = new CommandResult() { Message = e.Message, Status = CommandResult.StatusEnum.Fail }; return(result); } }
public async Task Edit() { var template = await this.Add(); var message = new HttpRequestMessage(HttpMethod.Put, API); var command = new TemplateChangeCommand { Id = template.Id, Format = this.GetConfig(), Name = this.GetRandom() }; message.AddJsonContent(command); var responseMessage = await this.HttpClient.SendAsync(message); await responseMessage.AsResult(); var newTemplate = await this.Get(template.Id); Assert.NotEqual(command.Name, template.Name); Assert.NotEqual(command.Format, template.Format); Assert.Equal(command.Name, newTemplate.Name); Assert.Equal(command.Format, newTemplate.Format); }
public async Task <object> Put(TemplateChangeCommand command) { await this._mediator.Send(command); return(ResponseResult.Success); }
public Task Handle(TemplateChangeCommand command) { return(this.Update(command.Id, s => s.Change(command))); }
public void Change(TemplateChangeCommand command) => this.Apply <TemplateChangeEvent>(command);
public async Task <CommandResult> SendCommand(TemplateChangeCommand command) { CommandResult commandResult = await _commandService.SendAndReceiveResult <CommandResult>(command); return(commandResult); }