public bool AddResultNotYetAcceptedByAthlete(ResultWebModel _result)
        {
            int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name);

            try
            {
                Result result = _result.ToResult();
                if (result.VenueID == 0)
                {
                    result.VenueID = null;
                }
                result.IsNotAcceptedByAthleteYet = true;
                if (result.OpponentAthleteID != myAthleteID)
                {
                    throw new Exception("OpponentAthleteID must be you");
                }
                if (result.AthleteID == myAthleteID)
                {
                    throw new Exception("AthleteID cannot be you");
                }

                db.Results.Add(result);
                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public List <ResultWebModel> ResultsAtVenue(int venueID)
        {
            var results = (from r in db.Results
                           where r.VenueID == venueID
                           where r.OpponentConfirmation != (int)OpponentConfirmationEnum.Declined
                           where r.IsDeleted == false
                           orderby r.Date descending
                           select r).ToList();

            return((from i in results
                    select ResultWebModel.FromResult(i)).ToList());
        }
        public List <ResultWebModel> Get(int athleteID)
        {
            var athlete = db.Athletes.SingleOrDefault(i => i.AthleteID == athleteID);

            var results = (from r in athlete.Results
                           where r.OpponentConfirmation != (int)OpponentConfirmationEnum.Declined
                           where r.IsNotAcceptedByAthleteYet == false
                           where r.IsDeleted == false
                           select r).ToList();

            return((from i in results
                    select ResultWebModel.FromResult(i)).ToList());
        }
        public List <ResultWebModel> ResultsNotYetAcceptedByMe()
        {
            int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name);

            var results = (from r in db.Results
                           where r.IsNotAcceptedByAthleteYet == true
                           where r.IsDeleted == false
                           orderby r.Date descending
                           select r).ToList();
            var model = (from i in results
                         select ResultWebModel.FromResult(i)).ToList();

            return(model);
        }
        public List <ResultWebModel> ResultsToConfirm()
        {
            int myAthleteID = new UserProfileLogic(db).GetAthleteIDForUserName(User.Identity.Name);

            var results = (from r in db.Results
                           where r.OpponentConfirmation == (int)OpponentConfirmationEnum.NotYet
                           where r.OpponentAthleteID == myAthleteID
                           where r.IsNotAcceptedByAthleteYet == false
                           where r.IsDeleted == false
                           orderby r.Date descending
                           select r).ToList();

            return((from i in results
                    select ResultWebModel.FromResult(i)).ToList());
        }
        public async Task <bool?> AddResultNotYetAcceptedByAthlete(ResultWebModel result)
        {
            string url = WebApiUrl + "Results/AddResultNotYetAcceptedByAthlete";

            try
            {
                string json = await this.sendPostRequestAndReceiveResponse(url, true);

                var modelResponse = JsonConvert.DeserializeObject <bool>(json);
                return(modelResponse);
            }
            catch (Exception exc)
            {
                LastExceptionUrl = url;
                LastException    = exc;
                return(null);
            }
        }
        public async Task <List <Result> > SyncResults(List <Result> resultsOnMobile)
        {
            string url = WebApiUrl + "Sync/SyncResults";

            try
            {
                var model = (from i in resultsOnMobile
                             select ResultWebModel.FromResult(i)).ToList();
                string json = await this.sendPostRequestAndReceiveResponse(url, model, true);

                var           modelResponse = JsonConvert.DeserializeObject <List <ResultWebModel> >(json);
                List <Result> syncedResults = (from i in modelResponse
                                               select i.ToResult()).ToList();
                return(syncedResults);
            }
            catch (Exception exc)
            {
                LastExceptionUrl = url;
                LastException    = exc;
                return(null);
            }
        }
Exemple #8
0
        async Task <bool> sendAllResultsByOpponents()
        {
            try
            {
                var results = repository.GetResultsForOtherAthletes();

                foreach (var result in results)
                {
                    bool?ok = await webservice.AddResultNotYetAcceptedByAthlete(ResultWebModel.FromResult(result));

                    if (ok == null)
                    {
                        return(false); // internet issues
                    }
                    repository.DeleteResult(result.ResultID);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        protected override async Task <SyncResult> sync()
        {
            if (Config.App != MobileAppEnum.SnookerForVenues)
            {
                throw new Exception("App = " + Config.App.ToString());
            }

            SyncResult syncRes = new SyncResult();

            syncRes.TimeStarted = DateTime.Now;
            syncRes.Info        = "test\r\n";

            try
            {
                /// scores
                ///

                onStatusChanged(false, 1, 4);
                System.Threading.Thread.Sleep(500);

                // load scores from local db
                List <Score> localScores = App.Repository.GetScores(false);

                // send these scores to the web service
                List <Score> persistedScores = await App.WebService.PersistScoresFVO(localScores);

                onStatusChanged(false, 2, 4);
                System.Threading.Thread.Sleep(500);

                // set all persisted scores as 'deleted'
                foreach (var score in persistedScores)
                {
                    var localScore = localScores.Where(i => i.Guid == score.Guid).FirstOrDefault();
                    if (localScore == null)
                    {
                        continue; // this shouldn't be happening
                    }
                    App.Repository.SetIsDeletedOnScore(localScore.ScoreID, true);
                }

                onStatusChanged(false, 3, 4);
                System.Threading.Thread.Sleep(500);

                /// results
                ///

                // load results from local db
                List <Result> localResults = App.Repository.GetResults(false);

                // send these results to the web service
                List <ResultWebModel> persistedResults = await App.WebService.PersistResultsFVO((from r in localResults
                                                                                                 select ResultWebModel.FromResult(r)).ToList());

                onStatusChanged(false, 4, 4);
                System.Threading.Thread.Sleep(500);

                // set all persisted results as 'deleted'
                foreach (var result in persistedResults)
                {
                    var localResult = localResults.Where(i => i.Guid == result.Guid).FirstOrDefault();
                    if (localResults == null)
                    {
                        continue; // this shouldn't be happening
                    }
                    App.Repository.SetIsDeletedOnResult(localResult.ResultID, true);
                }

                syncRes.Result        = SyncResultEnum.Ok;
                syncRes.TimeCompleted = DateTime.Now;
                return(syncRes);
            }
            catch (Exception exc)
            {
                syncRes.Result        = SyncResultEnum.Failed;
                syncRes.TimeCompleted = DateTime.Now;
                syncRes.Info         += "Exception: " + TraceHelper.ExceptionToString(exc);
                return(syncRes);
            }
        }
Exemple #10
0
        public List <ResultWebModel> SyncResults(List <ResultWebModel> resultsOnMobile)
        {
            Athlete athlete = this.getAthlete();

            // results on mobile
            List <Result> resultsOnMobile1 = (from r in resultsOnMobile
                                              select r.ToResult()).ToList();

            foreach (var result in resultsOnMobile1)
            {
                if (result.AthleteID != athlete.AthleteID)
                {
                    throw new Exception("athleteID !");
                }
            }
            foreach (var result in resultsOnMobile1)
            {
                if (result.VenueID == 0)
                {
                    result.VenueID = null;
                }
            }

            // results on the server
            List <Result> resultsOnServer = db.Results.Where(i => i.AthleteID == athlete.AthleteID).ToList();

            // update results on the server
            foreach (var resultOnMobile in resultsOnMobile1)
            {
                var resultOnServer = (from r in resultsOnServer
                                      where r.Guid == resultOnMobile.Guid
                                      select r).FirstOrDefault();

                if (resultOnServer == null)
                {
                    // note. new result on the mobile -> add on the server

                    if (resultOnMobile.VenueID == 0)
                    {
                        resultOnMobile.VenueID = null;
                    }
                    resultOnMobile.OpponentConfirmation = (int)OpponentConfirmationEnum.NotYet;

                    db.Results.Add(resultOnMobile);
                    db.SaveChanges();
                    continue;
                }

                if (resultOnServer.IsDifferent(resultOnMobile) &&
                    (resultOnMobile.TimeModified - resultOnServer.TimeModified).TotalSeconds > 1)
                {
                    // update on the server
                    resultOnServer.Count             = resultOnMobile.Count;
                    resultOnServer.Count2            = resultOnMobile.Count2;
                    resultOnServer.Time              = resultOnMobile.Time;
                    resultOnServer.Date              = resultOnMobile.Date;
                    resultOnServer.Notes             = resultOnMobile.Notes;
                    resultOnServer.TimeModified      = resultOnMobile.TimeModified;
                    resultOnServer.VenueID           = resultOnMobile.VenueID;
                    resultOnServer.Type1             = resultOnMobile.Type1;
                    resultOnServer.OpponentAthleteID = resultOnMobile.OpponentAthleteID;
                    resultOnServer.Details1          = resultOnMobile.Details1;
                    resultOnServer.IsDeleted         = resultOnMobile.IsDeleted;
                    if (resultOnServer.IsDeleted == false)
                    {
                        resultOnServer.OpponentConfirmation = (int)OpponentConfirmationEnum.NotYet; // once edited, a result should be confirmed/declined by the opponent again
                    }
                    db.SaveChanges();
                    continue;
                }
            }

            var results = (from i in db.Results
                           where i.AthleteID == athlete.AthleteID
                           where i.IsDeleted == false // do not send deleted items back to the mobile
                           select i).ToList();

            List <ResultWebModel> models = (from i in results
                                            select ResultWebModel.FromResult(i)).ToList();

            return(models);
        }