public CommandResult Criar(CriarRotaCommand command) { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Rota rota = Rota.Criar( DataString.FromString(command.Nome), DataString.FromNullableString(command.Composicao_Rota), DataString.FromNullableString(command.Observacao), command.Flag_Ativo); dataContext.Add(rota); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Criar(CriarMotoristaCommand command) { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Motorista motorista = Motorista.Criar(DataString.FromString(command.Nome), DataString.FromNullableString(command.Ajudante1), DataString.FromNullableString(command.Ajudante2), DataString.FromString(command.Placa), DataString.FromNullableString(command.Telefone1), DataString.FromNullableString(command.Telefone2)); dataContext.Add(motorista); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Criar(CriarMaterialCommand command) { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Material material = Material.Criar(DataString.FromString(command.Descricao), DataString.FromNullableString(command.Volume), DataString.FromNullableString(command.Material_Coletado), DataString.FromNullableString(command.Material_Coletado)); dataContext.Add(material); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Criar(CriarMesReferenciaCommand command) { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } MesReferencia mesRef = MesReferencia.Criar( DataString.FromString(command.MesAno), command.DataInicio, command.DataTermino, command.Ativo); dataContext.Add(mesRef); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Atualizar(AtualizarMesReferenciaCommand command) { string entityName = "MesReferencia"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } MesReferencia mesRef = dataContext.MesReferencia.FirstOrDefault(x => x.Cod_MesReferencia == command.Cod_MesReferencia); if (mesRef is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_MesReferencia))); } mesRef.Atualizar(DataString.FromString(command.MesAno), command.DataInicio, command.DataTermino, command.Ativo); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Atualizar(AtualizarClienteCommand command) { string entityName = "Cliente"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Cliente cliente = dataContext.Cliente.FirstOrDefault(x => x.Cod_Cliente == command.Cod_Cliente); if (cliente is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Cliente))); } cliente.Atualizar( DataString.FromString(command.CPF_CNPJ), DataString.FromString(command.NomeCompleto_RazaoSocial), DataString.FromString(command.Fantasia), DataString.FromNullableString(command.Insc_Estadual), DataString.FromNullableString(command.Logradouro), DataString.FromNullableString(command.Endereco), DataString.FromNullableString(command.Bairro), DataString.FromNullableString(command.Complemento), DataString.FromNullableString(command.Cidade), DataString.FromNullableString(command.CEP), DataString.FromNullableString(command.UF), DataString.FromNullableString(command.Telefones), DataString.FromNullableString(command.Funcao), command.Flag_Ativo, command.Email, DataString.FromNullableString(command.Observacao), DataString.FromNullableString(command.Referencia)); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Atualizar(AtualizarMotoristaCommand command) { string entityName = "Motorista"; string commandName = $"Atualizando {entityName}"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Motorista motorista = dataContext.Motorista.FirstOrDefault(x => x.Cod_Motorista == command.Cod_Motorista); if (motorista is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Motorista))); } if (dataContext.Motorista.Any(x => x.Nome == command.Nome.ToUpper() && x.Cod_Motorista != command.Cod_Motorista)) { string message = "Já existe um Motorista com este nome."; return(CommandResult.Invalid(message)); } motorista.Atualizar(DataString.FromString(command.Nome), DataString.FromNullableString(command.Ajudante1), DataString.FromNullableString(command.Ajudante2), DataString.FromString(command.Placa), DataString.FromNullableString(command.Telefone1), DataString.FromNullableString(command.Telefone2)); //if (material.HasNotifications) //{ // return CommandResult.Invalid(material.Notifications.ToNotificationsString()); //} dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Atualizar(AtualizarMaterialCommand command) { string entityName = "Material"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Material material = dataContext.Material.FirstOrDefault(x => x.Cod_Material == command.Cod_Material); if (material is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Material))); } if (dataContext.Material.Any(x => x.Descricao == command.Descricao.ToUpper() && x.Cod_Material != command.Cod_Material)) { string message = "Já existe outro Material com este nome."; return(CommandResult.Invalid(message)); } material.Atualizar(DataString.FromString(command.Descricao), command.Volume, DataString.FromNullableString(command.Material_Coletado), DataString.FromNullableString(command.Material_Coletado)); //if (material.HasNotifications) //{ // return CommandResult.Invalid(material.Notifications.ToNotificationsString()); //} dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Criar(CriarClienteCommand command) { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Cliente cliente = Cliente.Criar( DataString.FromString(command.CPF_CNPJ), DataString.FromString(command.NomeCompleto_RazaoSocial), DataString.FromString(command.Fantasia), DataString.FromNullableString(command.Insc_Estadual), DataString.FromNullableString(command.Logradouro), DataString.FromNullableString(command.Endereco), DataString.FromNullableString(command.Bairro), DataString.FromNullableString(command.Complemento), DataString.FromNullableString(command.Cidade), DataString.FromNullableString(command.CEP), DataString.FromNullableString(command.UF), DataString.FromNullableString(command.Telefones), DataString.FromNullableString(command.Funcao), command.Flag_Ativo, command.Email, DataString.FromNullableString(command.Observacao), DataString.FromNullableString(command.Referencia)); dataContext.Add(cliente); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }
public CommandResult Atualizar(AtualizarRotaCommand command) { string entityName = "Rota"; string commandName = $"Atualizando {entityName}"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Rota rota = dataContext.Rota.FirstOrDefault(x => x.Cod_Rota == command.Cod_Rota); if (rota is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Rota))); } if (dataContext.Rota.Any(x => x.Nome == command.Nome.ToUpper() && x.Cod_Rota != command.Cod_Rota)) { string message = "Já existe uma Rota com este nome."; return(CommandResult.Invalid(message)); } rota.Atualizar(DataString.FromString(command.Nome), DataString.FromNullableString(command.Composicao_Rota), DataString.FromNullableString(command.Observacao), command.Flag_Ativo); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }