From eeb1b8054b7510426fe339048e87b5eee255c8a8 Mon Sep 17 00:00:00 2001 From: Jade_VAN_BRABANDT Date: Tue, 30 May 2023 15:00:07 +0200 Subject: [PATCH] Fix : blabla code smells --- Sources/Persistance/Persistance.cs | 2 +- Sources/Stim.Model/Game.cs | 6 ++++-- Sources/Stim.Model/Manager.cs | 11 ++++++----- Sources/Stim.Model/User.cs | 18 +++++++++++------- Sources/Stim/AddGamePage.xaml.cs | 5 +++-- Sources/Stim/App.xaml.cs | 2 +- 6 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Sources/Persistance/Persistance.cs b/Sources/Persistance/Persistance.cs index 908a824..c5a2544 100644 --- a/Sources/Persistance/Persistance.cs +++ b/Sources/Persistance/Persistance.cs @@ -29,7 +29,7 @@ namespace StimPersistance throw new NotImplementedException(); } - public ObservableCollection LoadGame() + public ObservableCollection? LoadGame() { if (File.Exists("games.xml")) { diff --git a/Sources/Stim.Model/Game.cs b/Sources/Stim.Model/Game.cs index b379985..5aefca6 100644 --- a/Sources/Stim.Model/Game.cs +++ b/Sources/Stim.Model/Game.cs @@ -75,7 +75,7 @@ namespace Model public float Average { get; private set; } [DataMember] - public string? Lien { + public string Lien { get => lien; private set { @@ -83,7 +83,7 @@ namespace Model lien = value; } } - private string? lien; + private string lien; public Game(string name, string description, int year, List c_tags, string cover, string c_lien) { @@ -106,6 +106,7 @@ namespace Model public override int GetHashCode() { + if (string.IsNullOrWhiteSpace(Name)) return 0; return Name.GetHashCode(); } @@ -119,6 +120,7 @@ namespace Model public bool Equals(Game? other) { + if (string.IsNullOrWhiteSpace(Name)) return false; return other != null && Name.Equals(other.Name); } diff --git a/Sources/Stim.Model/Manager.cs b/Sources/Stim.Model/Manager.cs index cbb00ea..8b9e91f 100644 --- a/Sources/Stim.Model/Manager.cs +++ b/Sources/Stim.Model/Manager.cs @@ -4,25 +4,26 @@ namespace Model { public class Manager { - public IPersistance _persistance; + public IPersistance persistance; public ObservableCollection GameList { get;} public Manager(IPersistance persistance) { - _persistance = persistance; + persistance = persistance; GameList = persistance.LoadGame(); + if (GameList == null) { GameList = new ObservableCollection();} } public void AddGametoGamesList(Game game) { GameList.Add(game); - _persistance.SaveGame(GameList); + persistance.SaveGame(GameList); } public void RemoveGameFromGamesList(Game game) { GameList.Remove(game); - _persistance.SaveGame(GameList); + persistance.SaveGame(GameList); } /*public void LoadGames() @@ -31,7 +32,7 @@ namespace Model }*/ public void SaveGames() { - _persistance.SaveGame(GameList); + persistance.SaveGame(GameList); } } } diff --git a/Sources/Stim.Model/User.cs b/Sources/Stim.Model/User.cs index 4cb08f1..3c420f5 100644 --- a/Sources/Stim.Model/User.cs +++ b/Sources/Stim.Model/User.cs @@ -51,8 +51,8 @@ namespace Model } private string? password; - public int Role { get; } - private int role; + //public int Role { get; } + //private int role; public List Followed_Games { get; @@ -61,12 +61,16 @@ namespace Model public User(string username, string biographie, string email, string password) { - Username = username; - Biographie = biographie; - Email = email; - Password = password; + if (username == null) Username = "Default"; + else Username = username; + if (biographie == null) biographie = "Default"; + else Biographie = biographie; + if (email == null) email = "Default"; + else Email = email; + if (password == null) password = "Default"; + else Password = password; Followed_Games = new List(); - Role = 0; + //Role = 0; } public void AddReview(Game game, float rate, string text) { diff --git a/Sources/Stim/AddGamePage.xaml.cs b/Sources/Stim/AddGamePage.xaml.cs index 31cd40a..1b5e165 100644 --- a/Sources/Stim/AddGamePage.xaml.cs +++ b/Sources/Stim/AddGamePage.xaml.cs @@ -17,8 +17,9 @@ public partial class AddGamePage : ContentPage private void AddGame(object sender, EventArgs e) { int year; - if (string.IsNullOrEmpty(NameEntry.Text) || string.IsNullOrEmpty(DescriptionEntry.Text) || string.IsNullOrEmpty(YearEntry.Text) || !int.TryParse(YearEntry.Text, out year) || string.IsNullOrWhiteSpace(LinkEntry.Text) /*|| _ImgPath is null*/) return; - string imgName = "no_cover.png";//NameEntry.Text + ".png"; + string imgName = "no_cover.png"; + if (string.IsNullOrEmpty(NameEntry.Text) || string.IsNullOrEmpty(DescriptionEntry.Text) || string.IsNullOrEmpty(YearEntry.Text) || !int.TryParse(YearEntry.Text, out year) || string.IsNullOrWhiteSpace(LinkEntry.Text) /*|| _ImgPath is null*/) return; + //if (_ImgPath!=null) NameEntry.Text + ".png"; //System.IO.File.Copy(_ImgPath, /**/, true); ((App)App.Current).Manager.AddGametoGamesList(new Game(NameEntry.Text, DescriptionEntry.Text, year, new List { TagEntry1.Text, TagEntry2.Text, TagEntry3.Text }, imgName, LinkEntry.Text)); Navigation.RemovePage(this); diff --git a/Sources/Stim/App.xaml.cs b/Sources/Stim/App.xaml.cs index 1bfe84d..c60130b 100644 --- a/Sources/Stim/App.xaml.cs +++ b/Sources/Stim/App.xaml.cs @@ -20,7 +20,7 @@ public partial class App : Application window.Stopped += (s, e) => { - Manager._persistance = new Persistance(FileSystem.Current.AppDataDirectory); + Manager.persistance = new Persistance(FileSystem.Current.AppDataDirectory); var test = Manager; Manager.SaveGames(); };