Ejemplo n.º 1
0
Archivo: WoWBiz.cs Proyecto: duylt/wow
 public bool ChallengeWake(Challenge challenge, bool processed = false)
 {
     challenge = this.GetChallenge(challenge.Id);
     var todayChallenge = challenge.ChallegeDays.Where(cld => cld.Date.Date.Equals(DateTime.Now.Date)).FirstOrDefault();
     if (todayChallenge == null)
     {
         ChallegeDay day = new ChallegeDay
         {
             ChallengeId = challenge.Id,
             Date = DateTime.Now,
             Succeed = true,
             UserId = challenge.UserId,
             IsProcessed = processed
         };
         this._core.AddChallengeDay(day);
         challenge.ChallegeDays.Add(day);
     }
     //Process to post facebook challenge
     if (!processed)
     {
         TempBiz tempBiz = new TempBiz();
         tempBiz.ChallengeProcess(challenge);
     }
     return true;
 }
Ejemplo n.º 2
0
Archivo: WoWCore.cs Proyecto: duylt/wow
 public bool AddChallenge(Challenge challegen)
 {
     using (var entity = new WakeOrWasteEntities())
     {
         entity.Configuration.ProxyCreationEnabled = false;
         var rs = entity.Challenges.Add(challegen);
         entity.SaveChanges();
         return rs != null;
     }
 }
Ejemplo n.º 3
0
 private int TotalDonationAmount(Challenge challenge)
 {
     var failedDayNo = GetFailedDayNo(challenge);
     if (challenge.DonationAmount.HasValue)
         return failedDayNo * (int)challenge.DonationAmount;
     return 0;
 }
Ejemplo n.º 4
0
 private bool IsLastDate(Challenge challenge)
 {
     var lastDate = challenge.StartTime.Value.AddDays((double)challenge.Duration);
     if (DateTime.Now.Date < lastDate.Date && DateTime.Now.Month <= lastDate.Month)
     {
         return false;
     }
     return true;
 }
Ejemplo n.º 5
0
 private bool IsFullyAccomplished(Challenge challenge)
 {
     var successfulDayNo = GetSuccessfulDayNo(challenge);
     if (successfulDayNo == challenge.Duration)
         return true;
     return false;
 }
Ejemplo n.º 6
0
 private int GetSuccessfulDayNo(Challenge challenge)
 {
     return challenge.ChallegeDays.Count(cd => cd.Succeed);
 }
Ejemplo n.º 7
0
 private int GetFailedDayNo(Challenge challenge)
 {
     return challenge.ChallegeDays.Count(cd => !cd.Succeed);
 }
Ejemplo n.º 8
0
Archivo: WoWBiz.cs Proyecto: duylt/wow
 public bool AddChallenge(Challenge challenge)
 {
     return _core.AddChallenge(challenge);
 }
Ejemplo n.º 9
0
Archivo: WoWBiz.cs Proyecto: duylt/wow
 public bool UpdateChallenge(Challenge challenge)
 {
     return _core.UpdateChallenge(challenge);
 }
Ejemplo n.º 10
0
 public bool UpdateChallenge(Challenge challenge)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
Archivo: TempBiz.cs Proyecto: duylt/wow
        private void PostFailMessage(Challenge challenge)
        {
            List<string> failMessage = new List<string>
            {
                "I MISSED MY GOAL of waking up today. Please give your likes and comments below to encourage me to move on!",
            };

            List<string> failMessageDonate = new List<string>
            {
                "As part of the challenge on wakeorwaste.com, I have donated ${0} to the charity foundation {1}"
            };

            if (challenge.Donation != null)
            {
                PostStatus(challenge, string.Format(failMessageDonate[0], challenge.DonationAmount.Value.ToString(), challenge.Donation.Name));
            }
            else
            {
                PostStatus(challenge, failMessage[0]);
            }
        }
Ejemplo n.º 12
0
Archivo: TempBiz.cs Proyecto: duylt/wow
        public void ChallengeProcess(Challenge challenge)
        {
            try
            {
                var todayChallenge = challenge.ChallegeDays.Where(c => c.Date.Date.Equals(DateTime.Now.Date)).FirstOrDefault();
                #region Fail Message
                if (todayChallenge == null)
                {
                    var settingTime = DateTime.Now.Date;
                    settingTime = settingTime.AddHours(challenge.WakeUpTime.Value.Hours);
                    settingTime = settingTime.AddMinutes(challenge.WakeUpTime.Value.Minutes);

                    //Fail challenge when dont complete challenge before 10minutes after goal time
                    settingTime = settingTime.AddMinutes(10);
                    if (settingTime < DateTime.Now)
                    {
                        //Over 10 minutes but user still dont complete day challenge
                        Biz.ChallengeWaste(challenge, true);
                        PostFailMessage(challenge);
                        todayChallenge.IsProcessed = true;
                        Biz.UpdateChallengeDay(todayChallenge);
                        //#############################################
                    }
                }
                else
                {
                    if (todayChallenge.Succeed == false && todayChallenge.IsProcessed == false)
                    {
                        PostFailMessage(challenge);
                        todayChallenge.IsProcessed = true;
                        Biz.UpdateChallengeDay(todayChallenge);
                    }
                }
                //#############################################

                //Challenge InProgress
                #endregion

                //Success message
                if (challenge != null && todayChallenge != null)
                {
                    if (todayChallenge.Succeed && !todayChallenge.IsProcessed)
                    {
                        var successChallenges = challenge.ChallegeDays.Where(c => c.Succeed == true).ToList();

                        //Announcement 1st success
                        if (successChallenges.Count() == 1)
                        {
                            PostStatus(challenge, "I completed my very first challenge to wake up earlier!");
                            todayChallenge.IsProcessed = true;
                            Biz.UpdateChallengeDay(todayChallenge);
                        }

                        //Announcement 50% progress
                        if ((successChallenges.Count() / challenge.Duration.Value) >= 0.5)
                        {
                            PostStatus(challenge, "I completed 50% challenge to wake up earlier!");
                            todayChallenge.IsProcessed = true;
                            Biz.UpdateChallengeDay(todayChallenge);
                        }

                        //Perfect
                        if (successChallenges.Count() == challenge.Duration.Value)
                        {
                            PostStatus(challenge, "I completed 100% challenge to wake up earlier! I changed my habit!");
                            todayChallenge.IsProcessed = true;
                            Biz.UpdateChallengeDay(todayChallenge);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 13
0
Archivo: TempBiz.cs Proyecto: duylt/wow
 private void PostStatus(Challenge challenge, string message)
 {
     var clientId = challenge.User.Socials.First().ClientId_;
     var clientToken = challenge.User.Socials.First().Token;
     Fb.Post(clientId, clientToken, message);
 }
Ejemplo n.º 14
0
Archivo: WoWCore.cs Proyecto: duylt/wow
 public bool UpdateChallenge(Challenge challenge)
 {
     throw new NotImplementedException();
 }