public string Inserir(IngredienteCollection ingrediente) { var tryCount = 5; var success = false; string hashMongo = string.Empty; do { try { _ingredienteCollection.InsertOne(ingrediente); hashMongo = ingrediente.Id.ToString(); success = true; } catch (System.Exception) { tryCount--; Thread.Sleep(1000); if (tryCount == 0) { throw; } } } while (!success && tryCount > 0); return(hashMongo); }
public void Atualizar(IngredienteCollection ingrediente) { var tryCount = 5; var success = false; do { try { var filter = Builders <IngredienteCollection> .Filter.Eq(t => t.Id, ingrediente.Id); var update = Builders <IngredienteCollection> .Update .Set(t => t.Nome, ingrediente.Nome) .Set(t => t.Valor, ingrediente.Valor); _ingredienteCollection.UpdateOne(filter, update); success = true; } catch (System.Exception) { tryCount--; Thread.Sleep(1000); if (tryCount == 0) { throw; } } } while (!success && tryCount > 0); }
public static IngredienteResponse ConverteParaIngredienteResponse(IngredienteCollection ingredienteCollection) => new IngredienteResponse { Id = ingredienteCollection.Id.ToString(), Nome = ingredienteCollection.Nome, Valor = ingredienteCollection.Valor };