public void AtualizarModelo(Modelo modeloAtualizacao) { var modelo = Modelos.FirstOrDefault(entry => entry.Id == modeloAtualizacao.Id); if (modelo == null) { return; } modelo.AssignFields(modeloAtualizacao); SalvarModelo(modelo); }
public void SalvarModelo(Modelo modeloSave) { string m_Directory = BaseDirectoryModelo + @"\" + modeloSave.Id; Directory.CreateDirectory(m_Directory); using (StreamWriter sw = new StreamWriter(m_Directory + @"\modelo_" + modeloSave.Id + ".json")) using (JsonWriter writer = new JsonTextWriter(sw)) { writer.Formatting = Formatting.Indented; Serializer.Serialize(writer, modeloSave); } if (Modelos.Any(entry => entry.Id == modeloSave.Id)) { var oldModelo = Modelos.FirstOrDefault(entry => entry.Id == modeloSave.Id); Modelos.Remove(oldModelo); } Modelos.Add(modeloSave); }
public void RemoverModelo(Modelo modeloRemocao) { var model = Modelos.FirstOrDefault(entry => entry.Id == modeloRemocao.Id); if (model == null) { return; } Modelos.Remove(model); var modeloDirectory = Directory.GetDirectories(BaseDirectoryModelo).FirstOrDefault(entry => entry.Equals(BaseDirectoryModelo + @"\" + modeloRemocao.Id)); if (modeloDirectory == null || modeloDirectory.Length == 0) { return; } Directory.Delete(modeloDirectory, true); RemoveLancamentosModelo(modeloRemocao.Id); }