private JassActivityHistory ActivitySaveHistory(JassActivity activity, JassActivityReview review)
 {
     JassActivityHistory activityHistory = new JassActivityHistory();
     var mapper = new JassCommonAttributesMapper<JassActivityCommon, JassActivity, JassActivityHistory>();
     mapper.map(activity, activityHistory);
     activityHistory.JassActivityID = activity.JassActivityID;
     activityHistory.JassActivityReviewID = review.JassActivityReviewID;
     ActivityHistoryCreate(activityHistory);
     return activityHistory;
 }
        public List<JassActivity> ActivitiesArchiveGetAll()
        {
            var activities =  myActivities().ToList<JassActivity>();

            //before anything we find out the 'done day' of this task list

            DateTime? doneDate=null;
            foreach (var activity in activities)
            {
                if (activity.title == "A1 Mind") //bad hack. but..
                {
                    doneDate = activity.DoneDate;
                }
            }

            if (doneDate == null) return ActivitiesGetAll();

            //firt of all let's check some conditions
            //1. for now only one review a day
            DateTime doneDate2 = (DateTime)doneDate;
            var now = DateTime.Now;
            var existingReview = myActivityReviews().Where(r => r.ReviewYear == doneDate2.Year &&
                r.ReviewMonth == doneDate2.Month &&
                r.ReviewDay == doneDate2.Day).ToList();

            if (existingReview.Count>0) return ActivitiesGetAll();

            //2. Now, let's make sure all scheduled tasks are done or doneplus

            int tasks = 0; int stared = 0; int done = 0; int doneplus = 0;
            foreach (var activity in activities)
            {
                tasks++;
                if (activity.Status == "stared") {
                    stared++; };
                if (activity.Status == "done") done++;
                if (activity.Status == "doneplus") doneplus++;
            }

            //we will only accept a review if something is done and nothing is still stared

               // if ( (stared > 0) || (done + doneplus == 0) )return ActivitiesGetAll();

            var review = new JassActivityReview();
            _db.JassActivityReviews.Add(review);
            review.UserName = _username;
            review.ReviewDate = DateTime.Now;
            review.ReviewYear = doneDate2.Year;
            review.ReviewMonth = doneDate2.Month;
            review.ReviewDay = doneDate2.Day;

            _db.SaveChanges();

            foreach (var activity in activities)
            {
                var activityHistory = ActivitySave(activity,review);
                activity.Status="asleep";
                activity.DoneDate = null;
                ActivitySave(activity, false);
            }
            _db.SaveChanges();
            return ActivitiesGetAll();
        }
 public JassActivityHistory ActivitySave(JassActivity Activity, JassActivityReview review)
 {
     checkIfMine(Activity); checkIfMine(review);
     if (Activity.Status == null) Activity.Status = "asleep";
     if (Activity.LastUpdated == new DateTime()) { Activity.LastUpdated = DateTime.Now; }
     _db.Entry(Activity).State = EntityState.Modified;
     _db.SaveChanges();
     var activityHistory = ActivitySaveHistory(Activity, review);
     return activityHistory;
 }