예제 #1
0
    public bool ResumeMemberPlan(int myPlanId)
    {
        bool          ret = false;
        DIYPTEntities db  = new DIYPTEntities();

        try
        {
            db.Database.Connection.Open();

            MemberExercisePlan myPlan = (from c in db.MemberExercisePlans
                                         where c.Id == myPlanId
                                         select c).FirstOrDefault();
            if (myPlan == null)
            {
                return(ret);
            }

            IList <MemberExercisePlanWeek> myPlanWeeks = (from c in db.MemberExercisePlanWeeks
                                                          where c.MemberExercisePlanId == myPlan.Id && c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_SUSPENDED)
                                                          orderby c.Week
                                                          select c).ToList();
            int      idx            = 1;
            DateTime currentEndDate = PrizeCommonUtils.GetSystemDate();
            DateTime startDate      = PrizeCommonUtils.GetWeekStart(currentEndDate);
            DateTime endDate        = PrizeCommonUtils.GetWeekEnd(startDate);
            foreach (var myPlanWeek in myPlanWeeks)
            {
                if (idx == 1)
                {
                    if (myPlanWeek.StartDate <= startDate)
                    {
                        myPlanWeek.Status    = PrizeConstants.STATUS_PLAN_WEEK_STARTED;
                        myPlanWeek.StartDate = startDate;
                        myPlanWeek.EndDate   = endDate;
                    }
                    else
                    {
                        myPlanWeek.Status = PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED;
                        startDate         = myPlanWeek.StartDate;
                        endDate           = myPlanWeek.EndDate;
                    }
                }
                else
                {
                    myPlanWeek.Status    = PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED;
                    myPlanWeek.StartDate = startDate;
                    myPlanWeek.EndDate   = endDate;
                }
                myPlan.EndDate = endDate;
                startDate      = startDate.AddDays(7);
                endDate        = endDate.AddDays(7);
                idx++;
            }
            myPlan.Status = PrizeConstants.STATUS_PLAN_STARTED + myPlan.Status[1];

            db.SaveChanges();

            return(true);
        }
        catch
        {
            return(false);
        }
        finally
        {
            db.Dispose();
        }
    }