Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="forced">force reloading from web service</param>
        /// <returns>Sessions: list of Session</returns>
        public async static Task <List <Session> > LoadSessions(bool forced = false)
        {
            if (SportTypes == null)
            {
                await LoadSports();
            }
            if (Units == null)
            {
                await LoadUnits();
            }

            try
            {
                if (forced)
                {
                    Sessions = await WSConsumer.GetSessions(user.Id);
                }
                else
                {
                    Sessions = Sessions ?? await WSConsumer.GetSessions(user.Id);
                }
            }
            catch (Exception e)
            {
                DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
                Sessions = Sessions ?? await LoadList("session.json", Sessions);
            }

            Sessions.Sort((x, y) => x.CompareTo(y));
            return(Sessions);
        }
Example #2
0
 /// <summary>
 /// Load in the list Units the list of units from the Web service
 /// Or from the local file if the WS is not available
 /// </summary>
 /// <param name="forced">force the loading from the web service even if Units contains something</param>
 /// <returns>the static list Units of Unit</returns>
 public async static Task <List <Unit> > LoadUnits(bool forced = false)
 {
     try
     {
         if (forced)
         {
             Units = await WSConsumer.GetUnits();
         }
         else
         {
             Units = Units ?? await WSConsumer.GetUnits();
         }
     }
     catch (Exception e)
     {
         DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
         Units = Units ?? await LoadList("unit.json", Units);
     }
     return(Units);
 }
Example #3
0
 /// <summary>
 /// Load SportTypes from the WebService
 /// Or from the local file
 /// </summary>
 /// <param name="forced">force to reload</param>
 /// <returns>SportTypes: list of SportType</returns>
 public async static Task <List <SportType> > LoadSports(bool forced = false)
 {
     try
     {
         if (forced)
         {
             SportTypes = await WSConsumer.GetSports();
         }
         else
         {
             SportTypes = SportTypes ?? await WSConsumer.GetSports();
         }
     }
     catch (Exception e)
     {
         DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
         SportTypes = SportTypes ?? await LoadList("sport.json", SportTypes);
     }
     return(SportTypes);
 }
Example #4
0
        /// <summary>
        /// load the user corresponding to user_name
        /// return it
        /// </summary>
        /// <returns>loaded user</returns>
        public async static Task <User> LoadUser(string user_name, string pwd)
        {
            if (user == null)
            {
                user          = new User();
                user.Name     = user_name;
                user.Password = pwd;

                try
                {
                    user = await WSConsumer.GetUser(user_name);
                }
                catch (Exception e)
                {
                    DependencyService.Get <IMessage>().longtime(e.Message);
                }
            }

            return(user);
        }
Example #5
0
        /// <summary>
        /// Add a new sesion to the static list of sessions of the class
        /// Save the list in the corresponding file
        /// </summary>
        /// <param name="session">new session to add</param>
        public async static void SaveSession(Session session)
        {
            try
            {
                if (Sessions == null)
                {
                    Sessions = new List <Session>();
                }

                Sessions = await WSConsumer.AddSession(session, user.Id);
            }
            catch (Exception e)
            {
                DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
                if (Sessions == null)
                {
                    Sessions = new List <Session>();
                }

                Sessions.Add(session);
            }
            SaveList(Sessions, sessionFile);
        }
Example #6
0
        /// <summary>
        /// Add a new sportType to the webservice and reload ws sports list
        /// Or Add it to the local sportType list
        /// save the list localy
        /// </summary>
        /// <param name="sport">new sportType to add in SportTypes</param>
        public static async void SaveSport(SportType sport)
        {
            try
            {
                if (SportTypes == null)
                {
                    await LoadSports();
                }

                SportTypes = await WSConsumer.AddSport(sport);
            }
            catch (Exception e)
            {
                DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
                if (SportTypes == null)
                {
                    SportTypes = new List <SportType>();
                }

                SportTypes.Add(sport);
            }
            SaveList(SportTypes, sportFile);
        }
Example #7
0
        /// <summary>
        /// Add a new unit to the webservice and reload ws units list
        /// Or Add it to the local units list
        /// save the list localy
        /// </summary>
        /// <param name="unit">new unit to add in Units</param>
        public async static void SaveUnit(Unit unit)
        {
            try
            {
                if (Units == null)
                {
                    await LoadUnits();
                }

                Units = await WSConsumer.AddUnit(unit);
            }
            catch (Exception e)
            {
                DependencyService.Get <IMessage>().longtime("ERR: " + e.Message);
                if (Units == null)
                {
                    Units = new List <Unit>();
                }

                Units.Add(unit);
            }
            SaveList(Units, unitFile);
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newUser"></param>
        public async static void SaveUser(User newUser)
        {
            try
            {
                user = await WSConsumer.SaveUser(newUser);

                try
                {
                    IFileSystem fileSystem = FileSystem.Current;
                    IFolder     folder     = fileSystem.LocalStorage;
                    IFile       file       = await folder.CreateFileAsync(userFile, CreationCollisionOption.OpenIfExists);

                    await file.WriteAllTextAsync(JsonConvert.SerializeObject(user));
                }
                catch (Exception e2)
                {
                    DependencyService.Get <IMessage>().shorttime("ERROR : " + e2.Message);
                }
            }
            catch (Exception e)
            {
                DependencyService.Get <IMessage>().shorttime(e.Message);
            }
        }