private async Task SaveColonne() { NouvelleColonne.TableId = TableauModel.IdTable; if (TableauModel.Colonnes == null) { TableauModel.Colonnes = new List <ColonneModel>(); } if (TableauModel.Colonnes.Any()) { NouvelleColonne.IdColonne = TableauModel.Colonnes.Max(x => x.IdColonne) + 1; } // Si la valeur n'est pas null, c'est que l'utilisateur a modifié la valeur. if (NouvelleColonne.TypeData != null) { _saveValueType = NouvelleColonne.TypeData; } else { // Sinon il a gardé la même valeur que l'autre. NouvelleColonne.TypeData = _saveValueType; } TableauModel.Colonnes.Add(NouvelleColonne); NouvelleColonne = new ColonneModel(); }
public NewTableViewModel(CurrentUserService userService, IDataAccess dataAccess, NotificationService notification, NavigationManager navigationManager, IModalService modalSvc) { TableauModel = new TableauModelValidation(); TableauModel.IdTable = Guid.NewGuid(); NouvelleColonne = new ColonneModel(); CurrentUserService = userService; DataService = dataAccess; _notificationService = notification; ModalService = modalSvc; _navigationManager = navigationManager; }
/// <see cref="INewTableViewModel.CloseNewColonne"/> public void CloseNewColonne() { ShowNewColonne = false; NouvelleColonne = new ColonneModel(); }
/// <summary> /// Charge le tableau avec l'ID donné en paramètre. /// </summary> /// <param name="idTableau"></param> /// <returns></returns> public async Task <Tableau> GetTableau(string idTableau) { var commandSelectTableau = @"SELECT IdTableau, IdUser, NomTableau, DescriptionTable, DateFinInscription " + "FROM tableau " + $"WHERE IdTableau='{idTableau}';"; // Chargement de l'objet Tableau Func <MySqlCommand, Task <Tableau> > funcCmd = async(cmd) => { Tableau tableauResult = null; using (var reader = await cmd.ExecuteReaderAsync()) { while (reader.Read()) { tableauResult = new Tableau() { IdTableau = new Guid(reader.GetString(0)), IdUser = reader.GetString(1), NomDuTableau = reader.GetString(2), Description = reader.GetString(3), DateFinInscription = reader.GetDateTime(4) }; } } return(tableauResult); }; // Chargement des colonnes pour ce tableau var commandColonnes = @"SELECT col.IdColonne, col.NomColonne, col.DescriptionColonne, col.TypeData " + "FROM colonne col " + $"WHERE col.TableId='{idTableau}';"; Func <MySqlCommand, Task <List <ColonneModel> > > funcCmdColonne = async(cmd) => { List <ColonneModel> colonnes = new List <ColonneModel>(); using (var reader = await cmd.ExecuteReaderAsync()) { while (reader.Read()) { var colonne = new ColonneModel() { IdColonne = reader.GetInt32(0), NomColonne = reader.GetString(1), Description = reader.GetString(2), TypeData = reader.GetString(3), TableId = new Guid(idTableau) }; colonnes.Add(colonne); } } return(colonnes); }; try { var tableau = await GetCoreAsync <Tableau>(commandSelectTableau, funcCmd); if (tableau == null) { return(null); } var colonnes = await GetCoreAsync <List <ColonneModel> >(commandColonnes, funcCmdColonne); tableau.Colonnes = colonnes; return(tableau); } catch (Exception ex) { var exs = ex.Message; throw; } }