public override async Task <Command> Edit(Command command) { Command cmd = new Command(command); try { var dto = await SerializerAsync.DeserializeJson <TipoEntradaDto>(command.Json); var tipoEntrada = await MyRepository.GetById(cmd.EntityId); if (tipoEntrada != null) { tipoEntrada.Descricao = dto.Description; cmd.Cmd = ServerCommands.LogResultOk; cmd.Json = await SerializerAsync.SerializeJson(true); await MyRepository.Save(); } else { cmd.Cmd = ServerCommands.LogResultDeny; cmd.Json = await SerializerAsync.SerializeJson(false); } } catch (Exception e) { ConsoleEx.WriteError(e); } return(cmd); }
public override async Task <Command> Edit(Command command) { Command cmd = new Command(command); try { var dto = await SerializerAsync.DeserializeJson <ServicoDto>(command.Json); var servico = await MyRepository.GetById(cmd.EntityId); if (servico != null) { servico.UpdateEntity(dto); var unidadeMedidaRep = new Repository <UnidadeMedida>(Context); var unidadeMedida = await unidadeMedidaRep.GetById(dto.UnidadeMedidaId); if (unidadeMedida != null) { servico.UnidadeMedida = unidadeMedida; } var tipoServicoRep = new Repository <TipoServico>(Context); var tipoServico = await tipoServicoRep.GetById(dto.TipoServicoId); if (tipoServico != null) { servico.TipoServico = tipoServico; } var centroCustoRep = new Repository <CentroCustoSintetico>(Context); var centroCusto = await centroCustoRep.GetById(dto.CentroCustoId); if (centroCusto != null) { servico.CentroCusto = centroCusto; } cmd.Cmd = ServerCommands.LogResultOk; cmd.Json = await SerializerAsync.SerializeJson(true); await MyRepository.Save(); } else { cmd.Cmd = ServerCommands.LogResultDeny; cmd.Json = await SerializerAsync.SerializeJson(false); } } catch (Exception e) { ConsoleEx.WriteError(e); } return(cmd); }
public override async Task <Command> Edit(Command command) { Command cmd = new Command(command); try { var dto = await SerializerAsync.DeserializeJson <UserDadosDto>(command.Json); var cliente = await MyRepository.GetById(cmd.EntityId); if (cliente != null) { cliente.UpdateEntity(dto); var enderecoRep = new Repository <Endereco>(Context); var endereco = await enderecoRep.GetById(dto.Endereco.Id); if (endereco != null) { endereco.UpdateEntity(dto.Endereco); cliente.Endereco = endereco; } cmd.Cmd = ServerCommands.LogResultOk; cmd.Json = await SerializerAsync.SerializeJson(true); await MyRepository.Save(); } else { cmd.Cmd = ServerCommands.LogResultDeny; cmd.Json = await SerializerAsync.SerializeJson(false); } } catch (Exception e) { ConsoleEx.WriteError(e); } return(cmd); }