public async Task <ActionResult <MovimentoEstoqueDto> > GetByHumanCode(MovimentoEstoqueDto dto) { try { var myUsername = User.Identity.Name; if (ZZApiMain.VerifyUserAuthorize(myUsername)) { if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn)) { var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.GetById, EntityId = dto.Id, Tela = Tela, Json = await SerializerAsync.SerializeJson(dto) }); var responseCommand = await myConn.Zz.GetApiWaitCommand(myId); if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk)) { return(await SerializerAsync.DeserializeJson <MovimentoEstoqueDto>(responseCommand.Json)); } } } return(NotFound()); } catch (Exception e) { ConsoleEx.WriteError(e); return(NotFound()); } }
public override EntityDto ConvertDto() { try { var dto = new MovimentoEstoqueDto { Id = Id, Codigo = Codigo, Quantidade = Quantidade, ServicoId = ServicoId, EstoqueId = EstoqueId, Observacao = Observacao }; if (Servico != null) { dto.Servico = (ServicoDto)Servico.ConvertDto(); } if (Estoque != null) { dto.Estoque = (TipoDto)Estoque.ConvertDto(); } return(dto); } catch (Exception e) { ConsoleEx.WriteError(e); return(null); } }
public override EntityDto ConvertDto() { try { var dto = new MovimentoEstoqueDto { Id = Id, Codigo = Codigo, IsEntrada = IsEntrada, Quantidade = Quantidade, ServicoId = ServicoId, EstoqueId = EstoqueId, TipoEntradaId = TipoEntradaId, DataMovimento = DataMovimento, DocumentoId = DocumentoId, Observacao = Observacao, PlantaId = PlantaId }; if (Servico != null) { dto.Servico = (ServicoDto)Servico.ConvertDto(); } if (Estoque != null) { dto.Estoque = (TipoDto)Estoque.ConvertDto(); } if (TipoEntrada != null) { dto.TipoEntrada = (TipoDto)TipoEntrada.ConvertDto(); } return(dto); } catch (Exception e) { ConsoleEx.WriteError(e); return(null); } }
public async Task <bool> VerififyMovimentoEstoque(MovimentoEstoqueDto dto) { try { var movimentoEstoques = await MyRepository.Get(t => t.Codigo.Equals(dto.Codigo)); var servicoRep = new Repository <Servico>(Context); var servico = await servicoRep.GetById(dto.ServicoId); var tipoEntradaRep = new Repository <TipoEntrada>(Context); var tipoEntrada = await tipoEntradaRep.GetById(dto.TipoEntradaId); var estoqueRep = new Repository <Estoque>(Context); var estoque = await estoqueRep.GetById(dto.EstoqueId); if (movimentoEstoques == null || movimentoEstoques.Any()) { return(false); } if (tipoEntrada == null || estoque == null || servico == null) { ConsoleEx.WriteLine(ServerCommands.RequisitoNaoCadastrado); return(false); } if (!servico.ControlaEstoque) { ConsoleEx.WriteLine(ServerCommands.NaoControlaEstoque); return(false); } var entity = new MovimentoEstoque(); entity.UpdateEntity(dto); entity.Estoque = estoque; entity.Servico = servico; entity.TipoEntrada = tipoEntrada; var mySaldo = await GetSaldoEstoque(servico, estoque); int multiplicadorSaldo = 1; if (!entity.IsEntrada) { multiplicadorSaldo = -1; } if (mySaldo == null || mySaldo.Quantidade + (multiplicadorSaldo * entity.Quantidade) <= 0) { ConsoleEx.WriteLine(ServerCommands.SaldoInsuficiente); return(false); } return(true); } catch (Exception e) { ConsoleEx.WriteError(e); return(false); } }