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 Criar(CriarContratoCommand command) { string entityName = "Contrato"; { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Cliente cliente = dataContext.Cliente.FirstOrDefault(c => c.Cod_Cliente == command.CodCliente); if (cliente is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.CodCliente))); } Contrato contrato = Contrato.Criar( command.ColetaContratada, command.ValorLimite, command.ValorUnidade, DataString.FromNullableString(command.MotivoCancelamento), command.DataCancelamento, command.FlagTermino, command.DataInicio, command.DataTermino, cliente); dataContext.Add(contrato); 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 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)); } }
public virtual void Alterar(T entity) { dataContext.Entry(entity).State = EntityState.Modified; //edição dataContext.SaveChanges(); //executando }
public CommandResult Atualizar(AtualizarRoteiroCommand command) { string entityName = "Roteiro"; string commandName = $"Atualizando {entityName}"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } var roteiro = dataContext.Roteiro.FirstOrDefault(x => x.Cod_Roteiro == command.Cod_Roteiro); if (roteiro is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Roteiro", command.Cod_Roteiro))); } var cliente = dataContext.Cliente.FirstOrDefault(x => x.Cod_Cliente == command.Cod_Cliente); if (cliente is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Cliente", command.Cod_Cliente))); } var turno = dataContext.Turno.FirstOrDefault(x => x.Cod_Turno == command.Cod_Turno); if (turno is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Turno", (int)command.Cod_Turno))); } var rota = dataContext.Rota.FirstOrDefault(x => x.Cod_Rota == command.Cod_Rota); if (rota is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Rota", command.Cod_Rota))); } var motorista = dataContext.Motorista.FirstOrDefault(x => x.Cod_Motorista == command.Cod_Motorista); if (motorista is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Motorista", command.Cod_Motorista))); } var material = dataContext.Material.FirstOrDefault(x => x.Cod_Material == command.Cod_Material); if (material is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada("Material", (int)command.Cod_Material))); } roteiro.Atualizar(cliente, turno, rota, motorista, material, command.Segunda, command.Terca, command.Quarta, command.Quinta, command.Sexta, command.Sabado, command.Domingo, DataString.FromNullableString(command.Observacao)); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }