Beispiel #1
0
    static public void SaveSystemErrorLog(int memberId, int?memberPlanId, PrizeConstants.SystemErrorLevel level,
                                          string sWebPage, string sEvent, Exception ex)
    {
        using (DIYPTEntities db = new DIYPTEntities())
        {
            var log = new PrizeErrorLog();
            log.MemberId             = memberId;
            log.MemberExercisePlanId = memberPlanId;
            log.Page       = sWebPage;       //HttpContext.Current.Request.Url.AbsolutePath;'
            log.ErrorLevel = (int)level;
            log.LogDate    = PrizeCommonUtils.GetSystemDate();
            log.Event      = sEvent;

            // Get stack trace for the exception with source file information
            var st = new StackTrace(ex, true);
            // Get the top stack frame
            var frame = st.GetFrame(st.FrameCount - 1);
            // Get the line number from the stack frame
            var    line   = frame.GetFileLineNumber();
            string sError = ex.Message + " Line_" + frame.GetFileLineNumber() + "\r\n" + ex.StackTrace;

            log.Error      = sError;
            log.InnerError = "";
            if (ex.InnerException != null)
            {
                log.InnerError = ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
            }
            db.PrizeErrorLogs.Add(log);
            db.SaveChanges();
        }
    }
    public void PayMemberManualPayment(int weeklyPaymentId, int currentOrderId, int memberPlanId, string paymentConfirmation, string comment = "")
    {
        DIYPTEntities db = new DIYPTEntities();

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

            PrizeOrder          myCurrentOrder;
            MemberExercisePlan  myPlan;
            MemberManualPayment myManualPayment;
            DateTime            currentEndDate = PrizeCommonUtils.GetSystemDate();
            if (currentOrderId >= 0)
            {
                // Get Weekly payment.
                myManualPayment          = db.MemberManualPayments.Single(o => o.Id == weeklyPaymentId);
                myManualPayment.PaidDate = currentEndDate;
                myManualPayment.Comment  = comment;
                myManualPayment.Status   = PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT_APPROVED + myManualPayment.Status[1];
                // Get the order based on order id.
                myCurrentOrder = db.PrizeOrders.Single(o => o.OrderId == currentOrderId);
                // Update the order to reflect payment has been completed.
                myCurrentOrder.PaymentTransactionId = paymentConfirmation;

                myPlan        = db.MemberExercisePlans.Single(o => o.Id == myCurrentOrder.MemberPlanId);
                myPlan.Status = PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_PAID;


                if (myPlan.StartDate < currentEndDate)
                {
                    DateTime startDate = PrizeCommonUtils.GetNextWeekStart(currentEndDate);
                    DateTime endDate   = PrizeCommonUtils.GetWeekEnd(startDate);
                    myPlan.StartDate = startDate;
                    IList <MemberExercisePlanWeek> myPlanWeeks = (from c in db.MemberExercisePlanWeeks
                                                                  where c.MemberExercisePlanId == myPlan.Id
                                                                  orderby c.StartDate
                                                                  select c).ToList();
                    foreach (MemberExercisePlanWeek myPlanWeek in myPlanWeeks)
                    {
                        myPlanWeek.StartDate = startDate;
                        myPlanWeek.EndDate   = endDate;
                        myPlanWeek.Status    = PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED;
                        myPlan.EndDate       = endDate;
                        db.SaveChanges();

                        startDate = startDate.AddDays(7);
                        endDate   = endDate.AddDays(7);
                    }
                }
                // Save to DB.
                db.SaveChanges();
            }
        }
        finally
        {
            db.Dispose();
        }
    }
    public int ManualPaymentMemberPlanSetup(PrizeMember member, int memberPlanId, int exercisePlanId, string sManualPaymentMode)
    {
        DIYPTEntities db = new DIYPTEntities();

        try
        {
            db.Database.Connection.Open();
            var oldOrders = db.PrizeOrders.Where(o => (o.MemberPlanId == memberPlanId && o.PaymentTransactionId == null));
            db.PrizeOrders.RemoveRange(oldOrders);
            PrizeOrder myOrder = new PrizeOrder();
            myOrder.OrderDate      = PrizeCommonUtils.GetSystemDate();
            myOrder.Username       = member.Email;
            myOrder.FirstName      = member.Firstname;
            myOrder.LastName       = member.Surname;
            myOrder.Email          = member.Email;
            myOrder.Total          = 0;
            myOrder.MemberPlanId   = memberPlanId;
            myOrder.ExercisePlanId = exercisePlanId;
            db.PrizeOrders.Add(myOrder);

            MemberExercisePlan myPlan;
            if (myOrder.OrderId >= 0)
            {
                myPlan = db.MemberExercisePlans.Single(o => o.Id == myOrder.MemberPlanId);

                myPlan.Status = PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT;
                MemberManualPayment manualPayment         = null;
                string manualPaymentStatus                = PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT_NOT_APPROVED + sManualPaymentMode;
                List <MemberManualPayment> manualPayments = (from c in db.MemberManualPayments
                                                             where c.MemberId == member.UmbracoId && c.Status.StartsWith(PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT_NOT_APPROVED)
                                                             select c).ToList();
                foreach (var notPaidRecord in manualPayments)
                {
                    db.MemberManualPayments.Remove(notPaidRecord);
                    db.SaveChanges();
                }

                manualPayment                      = new MemberManualPayment();
                manualPayment.MemberId             = myPlan.MemberId;
                manualPayment.MemberExercisePlanId = myPlan.Id;
                manualPayment.CreatedDate          = PrizeCommonUtils.GetSystemDate();
                manualPayment.Status               = manualPaymentStatus;
                db.MemberManualPayments.Add(manualPayment);
            }
            db.SaveChanges();
            return(myOrder.OrderId);
        }
        finally
        {
            db.Dispose();
        }
    }
    static public void SaveMemberLoginLog(int memberId, int?memberPlanId, string sWebPage, string sEvent, string sError = null)
    {
        using (DIYPTEntities db = new DIYPTEntities())
        {
            PrizeMember member = (from table in db.PrizeMembers
                                  where table.UmbracoId == memberId
                                  select table).FirstOrDefault();

            var log = new PrizeMemberLog();
            log.MemberId             = memberId;
            log.MemberExercisePlanId = memberPlanId;
            log.Page    = sWebPage; //HttpContext.Current.Request.Url.AbsolutePath;
            log.LogDate = PrizeCommonUtils.GetSystemDate();
            log.Event   = sEvent;
            log.Error   = sError;
            db.PrizeMemberLogs.Add(log);

            //No longer needed here.

            /*
             * DateTime dtYesterdayStart = PrizeCommonUtils.GetDayStart(log.LogDate.AddDays(-1));
             * DateTime dtYesterdayEnd = PrizeCommonUtils.GetDayEnd(log.LogDate.AddDays(-1));
             * DateTime dtTodayStart = PrizeCommonUtils.GetDayStart(log.LogDate);
             * DateTime dtTodayterdayEnd = PrizeCommonUtils.GetDayEnd(log.LogDate);
             *
             * PrizeMemberLog todayLogin = (from table in db.PrizeMemberLogs
             *                           where table.MemberId == memberId && table.LogDate >= dtTodayStart && table.LogDate <= dtTodayterdayEnd
             *                           select table).FirstOrDefault();
             * if (todayLogin != null)
             *  return;
             *
             * PrizeMemberLog yesterdayLogin = (from table in db.PrizeMemberLogs
             *                               where table.MemberId == memberId && table.LogDate >= dtYesterdayStart && table.LogDate <= dtYesterdayEnd
             *                               select table).FirstOrDefault();
             * if (yesterdayLogin != null && member.ContinuousLogin < PrizeConstants.MAX_CONTINUOUS_LOGIN)
             *  member.ContinuousLogin++;
             * else
             *  member.ContinuousLogin = 1;
             *
             * if (member.ContinuousLogin >= PrizeConstants.MAX_CONTINUOUS_LOGIN)
             * {
             *  PrizeEmailWrapper.SendMemberConintuousLoginEmail(member);
             * }
             */

            db.SaveChanges();
        }
    }
Beispiel #5
0
    private static void DailyTasks()
    {
        DIYPTEntities db = new DIYPTEntities();

        try
        {
            PrizeEmailWrapper.ExercisePlan2DaysPriorToStartEmailTask();

            db.Database.Connection.Open();
            DateTime today = PrizeCommonUtils.GetDayStart(PrizeCommonUtils.GetSystemDate());

            PrizePollingTask task = (from c in db.PrizePollingTasks
                                     where c.TaskDate >= today && c.TaskType == (int)PrizeConstants.TasksType.DailyRedoAble
                                     select c).FirstOrDefault();

            if (task == null || task.Count < 2)
            {
                PrizeMemberPlanManager.UpdateMemberPlans();

                PrizeEmailWrapper.DailyEmailTask();

                if (task == null)
                {
                    task          = new PrizePollingTask();
                    task.Status   = "1";
                    task.TaskDate = PrizeCommonUtils.GetSystemDate();
                    task.TaskType = (int)PrizeConstants.TasksType.DailyRedoAble;
                    task.Count    = 1;
                    db.PrizePollingTasks.Add(task);
                }
                else
                {
                    task.Count++;
                }

                db.SaveChanges();
            }
        }
        catch (Exception e)
        {
            PrizeLogs.SaveSystemErrorLog(0, 0, PrizeConstants.SystemErrorLevel.LevelSerious, typeof(RegisteredEvents).ToString(), "DailyTasks", e.Message, e.InnerException == null ? "" : e.InnerException.Message);
            return;
        }
        finally
        {
            db.Database.Connection.Close();
        }
    }
Beispiel #6
0
 static public void SaveSystemErrorLog(int memberId, int?memberPlanId, PrizeConstants.SystemErrorLevel level,
                                       string sWebPage, string sEvent, string sError, string sInnerError)
 {
     using (DIYPTEntities db = new DIYPTEntities())
     {
         var log = new PrizeErrorLog();
         log.MemberExercisePlanId = memberId;
         log.MemberExercisePlanId = memberPlanId;
         log.Page       = sWebPage;       //HttpContext.Current.Request.Url.AbsolutePath;'
         log.ErrorLevel = (int)level;
         log.LogDate    = PrizeCommonUtils.GetSystemDate();
         log.Event      = sEvent;
         log.Error      = sError;
         log.InnerError = sInnerError;
         db.PrizeErrorLogs.Add(log);
         db.SaveChanges();
     }
 }
Beispiel #7
0
    private void FillDate()
    {
        //DateTime tempdate = new DateTime(2017, 1, 10);
        //var nextSunday = tempdate.Next(DayOfWeek.Sunday);
        PrizeDataAccess db = new PrizeDataAccess();

        var exercisePlan = db.GetCurrentMemberPlanOrStartingPlan(PrizeMemberAuthUtils.GetMemberID());

        //var nextSunday = exercisePlan.StartDate.NextDay(DayOfWeek.Monday);
        if (exercisePlan == null)
        {
            return;
        }

        //var nextSunday = exercisePlan.StartDate.NextDay(DayOfWeek.Sunday);

        var nextSunday = exercisePlan.StartDate;
        int counter    = 0;

        for (int i = 0; i < 14; i++)
        {
            Label dateLabel = this.FindControl(string.Format("week{0}Date", i)) as Label;
            if (dateLabel != null)
            {
                dateLabel.Text = nextSunday.AddDays((i - 1) * 7).Date.ToString("dd/MM") + "-" + nextSunday.AddDays((i * 7) - 1).Date.ToString("dd/MM");
            }
            for (int d = 1; d <= 7; d++)
            {
                if (nextSunday.AddDays(counter).Date == PrizeCommonUtils.GetSystemDate().Date)
                {
                    HtmlTableCell tempLabel = this.FindControl(string.Format("w{0}d{1}", i, d)) as HtmlTableCell;
                    if (tempLabel != null)
                    {
                        tempLabel.Attributes.Add("class", tempLabel.Attributes["class"] + " active");
                    }
                }
                //Label tempLabel = this.FindControl(string.Format("week{0}_{1}", i, d)) as Label;
                //if (tempLabel != null)
                //    tempLabel.Text = nextSunday.AddDays(counter).ToString("dd/M");
                counter++;
            }
        }
    }
    private void doNoPaymentPlan()
    {
        PrizeOrder myOrder = new PrizeOrder();

        myOrder.OrderDate      = PrizeCommonUtils.GetSystemDate();
        myOrder.Username       = PrizeMemberAuthUtils.GetMemberName();
        myOrder.FirstName      = "";
        myOrder.LastName       = "";
        myOrder.Email          = PrizeMemberAuthUtils.GetMemberEmail();
        myOrder.Total          = 0;
        myOrder.MemberPlanId   = Int32.Parse(Session["buying_my_plan_id"].ToString());
        myOrder.ExercisePlanId = Int32.Parse(Session["buying_plan_id"].ToString());

        // Get DB context.
        DIYPTEntities _db = new DIYPTEntities();

        try
        {
            // Add order to DB.
            _db.Database.Connection.Open();
            _db.PrizeOrders.Add(myOrder);
            _db.SaveChanges();
            Session["currentOrderId"] = myOrder.OrderId;
        }
        finally
        {
            _db.Database.Connection.Close();
        }
        int currentOrderId = -1;

        if (Session["currentOrderId"] != string.Empty)
        {
            currentOrderId = Convert.ToInt32(Session["currentOrderID"]);
        }

        PrizeMemberPlanManager planManager = new PrizeMemberPlanManager();

        planManager.PayMemberPlans(currentOrderId, "");

        Response.Redirect(PrizeConstants.URL_MEMBER_LANDING);
    }
Beispiel #9
0
    private static void DoSendShceduledEmail()
    {
        DIYPTEntities db = new DIYPTEntities();

        try
        {
            db.Database.Connection.Open();
            IQueryable <MemberEmail> emails = (from c in db.MemberEmails
                                               where c.Status == (int)PrizeConstants.EmailStatus.Shceduled || c.Status == (int)PrizeConstants.EmailStatus.Failed
                                               select c);
            bool bSent = false;
            foreach (MemberEmail email in emails.ToList())
            {
                string        sError;
                List <string> additionalContents = new List <string>();
                additionalContents.Add(email.Content1);
                additionalContents.Add(email.Content2);
                additionalContents.Add(email.Content3);
                additionalContents.Add(email.Content4);
                additionalContents.Add(email.Content5);
                bSent = PrizeEmailServiceThread.SendEmailHandler(email, (PrizeConstants.EmailType)email.EmailType, email.Title, additionalContents);

                if (bSent)
                {
                    email.Status   = (int)PrizeConstants.EmailStatus.Succeeded;
                    email.SendDate = PrizeCommonUtils.GetSystemDate();
                    db.SaveChanges();
                }
                else
                {
                    email.SendDate = PrizeCommonUtils.GetSystemDate();
                    email.Status   = (int)PrizeConstants.EmailStatus.Failed;
                    db.SaveChanges();
                }
            }
        }
        finally
        {
            db.Database.Connection.Close();
        }
    }
    public void TerminateMemberManualPaymentPlan(int weeklyPaymentId, int memberPlanId, string comment = "")
    {
        DIYPTEntities db = new DIYPTEntities();

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

            MemberExercisePlan  myPlan;
            MemberManualPayment myManualPayment;
            DateTime            currentEndDate = PrizeCommonUtils.GetSystemDate();

            // Get Weekly payment.
            myManualPayment = db.MemberManualPayments.Single(o => o.Id == weeklyPaymentId);
            myManualPayment.TerminatedDate = currentEndDate;
            myManualPayment.Comment        = comment;
            myManualPayment.Status         = PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT_TERMINATED + myManualPayment.Status[1];

            myPlan        = db.MemberExercisePlans.Single(o => o.Id == memberPlanId);
            myPlan.Status = PrizeConstants.STATUS_PLAN_TERMINATED + myPlan.Status[1];

            IList <MemberExercisePlanWeek> myPlanWeeks = (from c in db.MemberExercisePlanWeeks
                                                          where c.MemberExercisePlanId == myPlan.Id && !c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_FINISHED)
                                                          orderby c.StartDate
                                                          select c).ToList();
            foreach (MemberExercisePlanWeek myPlanWeek in myPlanWeeks)
            {
                myPlanWeek.Status = PrizeConstants.STATUS_PLAN_WEEK_TERMINATED;
                db.SaveChanges();
            }

            // Save to DB.
            db.SaveChanges();
        }
        finally
        {
            db.Dispose();
        }
    }
Beispiel #11
0
    // Log an Exception
    public static void LogException(Exception exc, string source)
    {
        // Include logic for logging exceptions
        // Get the absolute path to the log file
        string logFile = "/App_Data/ErrorLog.txt";

        logFile = HttpContext.Current.Server.MapPath(logFile);

        // Open the log file for append and write the log
        StreamWriter sw = new StreamWriter(logFile, true);

        sw.WriteLine("********** {0} **********", PrizeCommonUtils.GetSystemDate());
        if (exc.InnerException != null)
        {
            sw.Write("Inner Exception Type: ");
            sw.WriteLine(exc.InnerException.GetType().ToString());
            sw.Write("Inner Exception: ");
            sw.WriteLine(exc.InnerException.Message);
            sw.Write("Inner Source: ");
            sw.WriteLine(exc.InnerException.Source);
            if (exc.InnerException.StackTrace != null)
            {
                sw.WriteLine("Inner Stack Trace: ");
                sw.WriteLine(exc.InnerException.StackTrace);
            }
        }
        sw.Write("Exception Type: ");
        sw.WriteLine(exc.GetType().ToString());
        sw.WriteLine("Exception: " + exc.Message);
        sw.WriteLine("Source: " + source);
        sw.WriteLine("Stack Trace: ");
        if (exc.StackTrace != null)
        {
            sw.WriteLine(exc.StackTrace);
            sw.WriteLine();
        }
        sw.Close();
    }
    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();
        }
    }
Beispiel #13
0
    private void AddNewUserDetails(int newUserId)
    {
        using (DIYPTEntities db = new DIYPTEntities())
        {
            db.Database.Connection.Open();
            try
            {
                PrizeMember member = new PrizeMember();

                member.Firstname = txtFirstName.Text;
                member.Surname   = tbLastName.Text;
                member.Email     = txtEmail.Text;

                member.StreetAddress = tbStreetAddress.Text;
                member.Suburb        = tbSuburb.Text;
                member.State         = tbState.Text;
                member.Country       = ddCountry.Text;
                member.Postcode      = tbPostCode.Text;
                member.Mobile        = tbMobile.Text;
                member.Phone         = tbPhone.Text;

                StringBuilder sb = new StringBuilder();
                sb.Append(Q3.InnerText);
                sb.Append("\r\n");
                sb.Append(ddlQ3.Text);
                sb.Append("\r\n");
                sb.Append(Q4.InnerText);
                sb.Append("\r\n");
                sb.Append(ddlQ4.Text);
                sb.Append("\r\n");
                sb.Append(regQ4.InnerText);
                sb.Append("\r\n");
                sb.Append(Q5.InnerText);
                sb.Append("\r\n");
                sb.Append(regQ5.InnerText);
                sb.Append("\r\n");
                sb.Append(ddlQ6.Text);
                sb.Append("\r\n");
                sb.Append(regQ6.InnerText);
                sb.Append("\r\n");
                sb.Append(ddlQ7.Text);
                sb.Append("\r\n");
                sb.Append(regQ7.InnerText);
                sb.Append("\r\n");

                member.Questions = sb.ToString();

                member.UmbracoId        = newUserId;
                member.RegisterDateTime = PrizeCommonUtils.GetSystemDate();
                char c = '1';
                if (!cbPromotionalPhoto.Checked)
                {
                    c = '0';
                }
                member.UserSettings = PrizeConstants.DEFAULT_MEMBER_SETTINGS;
                string s = string.Copy(member.UserSettings);
                PrizeMemberAuthUtils.SetMemberSetting(ref s, PrizeConstants.MemberSettings.PromotionalPhoto, c);
                member.UserSettings = s;
                db.PrizeMembers.Add(member);
                db.SaveChanges();
            }
            finally
            {
                db.Database.Connection.Close();
            }
        }
    }
Beispiel #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /*
         *     //Handled in BaseOrientation//
         *     if (PrizeMemberAuthUtils.CurrentUserLogin() != true)
         * return;
         */
        int memberId = PrizeMemberAuthUtils.GetMemberID();

        var exercisePlan = dbAccess.GetCurrentMemberPlanOrStartingPlan(memberId);

        if (exercisePlan == null)
        {
            PrizeMember            member  = PrizeMemberAuthUtils.GetMemberData(memberId);
            PrizeMemberPlanManager planMan = new PrizeMemberPlanManager();
            Response.Redirect(planMan.GetEmptyPlanJumpURL(member));
        }
        InitLables();
        //var member = PrizeMemberAuthUtils.GetMemberData();
        //lblTest.Text = member.Questions;


        if (Request["MemberPlanWeekID"] != null)
        {
            int memberPlanWeekId;
            int.TryParse(Request["MemberPlanWeekID"], out memberPlanWeekId);

            memberPlanWeek = dbAccess.GetMemberPlanWeekById(memberPlanWeekId);

            planWeek = dbAccess.GetExercisePlanWeek(memberPlanWeek.ExercisePlanWeekId);
        }
        else
        {
            DateTime now = PrizeCommonUtils.GetSystemDate();

            memberPlanWeek = dbAccess.GetCurrentMemberPlanWeek(memberId); //(MemberExercisePlanWeek)Session["MemberPlanWeek"];
            if (memberPlanWeek == null && PrizeCommonUtils.LessThanDaysAhead(now, exercisePlan.StartDate, 1))
            {
                memberPlanWeek = dbAccess.GetMemberPlanWeekByMemberPlanAndWeek(exercisePlan.Id, 0);
            }

            if (memberPlanWeek == null)
            {
                HideLinks();
                topInfo.Visible            = false;
                dayPre.Visible             = false;
                dayNext.Visible            = false;
                dayView.Visible            = false;
                printDay.Visible           = false;
                timesaverDiv.Visible       = false;
                timesaverDivMobile.Visible = false;
                divNotStarted.Visible      = true;
                return;
            }
            divNotStarted.Visible = false;

            planWeek = dbAccess.GetExercisePlanWeek(memberPlanWeek.ExercisePlanWeekId);
        }

        currentPlanWeekId = (int)memberPlanWeek.ExercisePlanWeekId;
        //
        dayView.HRef = dbAccess.GetCurrentDailyViewURL(memberId);
        LoadWeeklyInfo(memberId, planWeek, memberPlanWeek);

        MemberExercisePlan     myPlan   = dbAccess.GetMemberExercisePlan(memberPlanWeek.MemberExercisePlanId);
        MemberExercisePlanWeek prevWeek = dbAccess.GetMemberPlanWeekByMemberPlanAndWeek(myPlan.Id, memberPlanWeek.Week - 1);

        if (prevWeek != null)
        {
            dayPre.NavigateUrl = "/my-account/exercise-view?MemberPlanWeekID=" + prevWeek.Id;
            dayPre.Text        = "Week " + (memberPlanWeek.Week - 1);
        }
        else
        {
            dayPre.Attributes.Add("class", "no-arrow");
        }

        MemberExercisePlanWeek nextWeek = dbAccess.GetMemberPlanWeekByMemberPlanAndWeek(myPlan.Id, memberPlanWeek.Week + 1);

        if (nextWeek != null)
        {
            dayNext.NavigateUrl = "/my-account/exercise-view?MemberPlanWeekID=" + nextWeek.Id;
            dayNext.Text        = "Week " + (memberPlanWeek.Week + 1);
        }
        else
        {
            dayNext.Attributes.Add("class", "no-arrow");
        }
    }
Beispiel #15
0
    protected void LoadDailyInfo(int iMemberId, PrizeExercisePlanWeek planWeek)
    {
        //lblExercise.Text = dbWeek.Description;
        //lblWeek.Text = dbWeek.Week.ToString();

        foreach (var lbl in labels)
        {
            lbl.Text = PrizeConstants.STR_NO_TRAINNING;
        }

        DataSet ds = dbAccess.GetMemberWeeklyInfo(planWeek.Id);

        int DayTimeTypeId1 = 0;

        //int DayTimeTypeId2 = 0;
        foreach (DataRow row in ds.Tables[0].Rows)
        {
            int iWeekDay     = (int)row[0] - 1;
            int iDayTimeType = (int)row[1]; //(int)reader.GetInt32(3);

            if (iWeekDay < labels.Count)
            {
                int iIndex = iWeekDay;
                //if (iDayTimeType == DayTimeTypeId2)
                //iIndex += 7;
                labels[iIndex].Text = (String)row[2];//reader.GetString(1);
            }

            //if (iWeekDay == (int)(PrizeCommonUtils.GetSystemDate().DayOfWeek))
            //exerciseUnitSets.Add((int)row[4]); //((int)reader.GetInt32(4));
        }

        HtmlControl temp  = (HtmlControl)FindControl("day" + (int)(PrizeCommonUtils.GetSystemDate().GetDayOfWeek()));
        HtmlControl tempe = (HtmlControl)FindControl("day" + (int)(PrizeCommonUtils.GetSystemDate().GetDayOfWeek()) + "e");

        /*if (temp != null)
         * {
         *  temp.Attributes.Add("style", "background-color: #eee");
         *  tempe.Attributes.Add("style", "background-color: #eee");
         * }
         */
        for (int i = 0; i < 7; i++)
        {
            DataSet dsDaily       = dbAccess.GetExerciseUnitsSetDetail(planWeek.Id, i + 1);
            double  dTimeDuration = 0;
            int     iTimeDuration = 0;
            for (int j = 1; j < dsDaily.Tables.Count; j++)
            {
                foreach (DataRow row in dsDaily.Tables[j].Rows)
                {
                    dTimeDuration += double.Parse(row["TimeDuration"].ToString());
                    iTimeDuration  = (int)Math.Ceiling((double)dTimeDuration / 60);
                }
            }
            if (dsDaily.Tables.Count > 1)
            {
                iTimeDuration = iTimeDuration + 10 + 5; // +10 warm up; +5 cool down
            }
            lblTimeDuration[i].Text = "" + iTimeDuration;
        }

        for (int i = 0; i < 7; i++)
        {
            switch (labels[i].Text.Trim())
            {
            case "Brisk walk":
                lblTimeDuration[i].Text = "30 mins";
                break;

            case "Own 1hr cardio":
            case "Own training":
            case "Own cardio":
                lblTimeDuration[i].Text = "60 mins";
                break;

            case "30-60min weekend physical activity":
            case "Weekend physical activity":
                lblTimeDuration[i].Text = "30-60 mins";
                break;

            case "Rest Day":
                lblTimeDuration[i].Text = "All Day";
                break;

            default:
                lblTimeDuration[i].Text += " mins";
                break;
            }
        }
    }
Beispiel #16
0
    protected void LoadWeeklyInfo(int memberID, PrizeExercisePlanWeek planWeek, MemberExercisePlanWeek memberPlanWeek)
    {
        dayNumber = PrizeCommonUtils.GetSystemDate().GetDayOfWeek();

        int memberId = PrizeMemberAuthUtils.GetMemberID();

        using (DIYPTEntities db = new DIYPTEntities())
        {
            db.Database.Connection.Open();

            lblDateDuration.Text = PrizeCommonUtils.ParseDateToEnglish(memberPlanWeek.StartDate) + " - "
                                   + PrizeCommonUtils.ParseDateToEnglish(memberPlanWeek.EndDate);

            for (int i = 0; i < lblDates.Count; i++)
            {
                lblDates[i].Text = PrizeCommonUtils.ParseShortDateToEnglish(memberPlanWeek.StartDate.AddDays(i));
                HyperLink linkDay = FindControl("linkDay" + (i + 1)) as HyperLink;
                if (linkDay != null && planWeek != null)
                {
                    linkDay.NavigateUrl = (String.Format("{0}?PlanWeekId={1}&MemberPlanWeekId={2}&PlanDayNumber={3}", PrizeConstants.URL_MEMBER_DAY_VIEW, planWeek.Id, memberPlanWeek.Id, i + 1));
                }
                else if (planWeek == null)
                {
                    //Orientation week
                    linkDay.NavigateUrl = "/orientation/day-" + (i + 1);
                    labels[i].Text      = "Orientation day " + (i + 1);
                }
            }
            if (planWeek == null)
            {
                lblWeekNum.Text = "Week 0";
                PrizeDataAccess dba = new PrizeDataAccess();
                if (dba.MemberInOrientation(PrizeMemberAuthUtils.GetMemberID()))
                {
                    topInfo.Visible = false;
                }
                db.Database.Connection.Close();
                return;
            }

            int iWeekNum = memberPlanWeek.Week;
            lblWeekNum.Text = "Week " + iWeekNum;

            string[] planWeekDesc      = planWeek.Description.Split('\n');
            bool     bEquipmentSession = false;
            if (strEquipments == null)
            {
                strEquipments = new List <string>();
            }
            for (int i = 0; i < planWeekDesc.Length; i++)
            {
                string[] strKeyValue = planWeekDesc[i].Split(':');
                if (strKeyValue != null && strKeyValue.Length > 1)
                {
                    if ((i == 1) && (strKeyValue[0].IndexOf("phase", StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        lblTrainingPhase.Text = strKeyValue[1];
                        continue;
                    }
                    if ((i == 2) && (strKeyValue[0].IndexOf("phase duration", StringComparison.OrdinalIgnoreCase) >= 0 || (strKeyValue[0].IndexOf("training duration", StringComparison.OrdinalIgnoreCase) >= 0)))
                    {
                        lblDuration.Text = strKeyValue[1];
                        continue;
                    }

                    if (strKeyValue[0].IndexOf("equipment", StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        bEquipmentSession = true;
                        strEquipments.Clear();
                        continue;
                    }
                }

                if (bEquipmentSession && Regex.Matches(planWeekDesc[i], @"[a-zA-Z]").Count > 0)
                {
                    strEquipments.Add(planWeekDesc[i]);
                    continue;
                }
            }

            if (strEquipments != null && strEquipments.Count > 0)
            {
                string tempLiteral = "<ul class='equipment-list'>";
                foreach (var e in strEquipments)
                {
                    if (e != " ")
                    {
                        tempLiteral += "<li>" + e + "</li>";
                    }
                }
                tempLiteral                += "</ul>";
                equipmentLiteral.Text       = tempLiteral;
                equipmentLiteralMobile.Text = tempLiteral;
                equipmentDiv.Visible        = true;
            }

            DataSet myPlan = dbAccess.GetExercisePlanInfo((int)planWeek.ExercisePlanId);
            if (myPlan.Tables[0].Rows.Count == 0)
            {
                db.Database.Connection.Close();
                return;
            }

            this.lblGoal.Text = myPlan.Tables[0].Rows[0]["ProgramName"].ToString();


            LoadDailyInfo(memberId, planWeek);

            //PrizePlanProgram myProgram = (from c in db.PrizePlanPrograms
            //                              where c.Id == planWeek.ExercisePlanId
            //                              select c).FirstOrDefault();


            db.Database.Connection.Close();
        }
    }
Beispiel #17
0
    public string GetCurrentDailyViewURL(int memberId)
    {
        string result = "";
        MemberExercisePlanWeek memberPlanWeek = GetCurrentMemberPlanWeek(memberId);

        if (memberPlanWeek == null)
        {
            return(result);
        }
        PrizeExercisePlanWeek planWeek = GetExercisePlanWeek(memberPlanWeek.ExercisePlanWeekId);

        if (planWeek == null)
        {
            return(result);
        }
        result = String.Format("{0}?PlanWeekId={1}&MemberPlanWeekId={2}&PlanDayNumber={3}", PrizeConstants.URL_MEMBER_DAY_VIEW, planWeek.Id, memberPlanWeek.Id, PrizeCommonUtils.GetSystemDate().GetDayOfWeek());
        return(result);
    }
 protected void refresh2(object sender, EventArgs e)
 {
     tbFirstName2.Text = string.Empty;
     clWeeklyPaymentStop1.SelectedDate = PrizeCommonUtils.GetSystemDate();
     clWeeklyPaymentStop2.SelectedDate = PrizeCommonUtils.GetSystemDate();
 }
 protected void refresh(object sender, EventArgs e)
 {
     tbfistname.Text = string.Empty;
     clWeeklyPaymentStart1.SelectedDate = PrizeCommonUtils.GetSystemDate();
     clWeeklyPaymentStart2.SelectedDate = PrizeCommonUtils.GetSystemDate();
 }
    public int BuyNewPlan(int newPlanId, ref PrizeExercisePlan prizePlan, ref MemberExercisePlan newMemberPlan)
    {
        DIYPTEntities db = new DIYPTEntities();

        try
        {
            if (PrizeMemberAuthUtils.CurrentUserLogin() != true)
            {
                return(PrizeErrorCode.ERROR_NOT_LOGGED_IN);
            }
            int memberId = PrizeMemberAuthUtils.GetMemberID();

            db.Database.Connection.Open();

            PrizeExercisePlan plan = (from c in db.PrizeExercisePlans
                                      where c.Id == newPlanId
                                      select c).FirstOrDefault();

            if (plan == null)
            {
                return(-1);
            }

            //using (TransactionScope transaction = new TransactionScope())
            //{
            if (plan == null)
            {
                return(PrizeErrorCode.ERROR_PLAN_NOT_EXIST);
            }

            MemberExercisePlan myExistingPaidPlan = (from c in db.MemberExercisePlans
                                                     where c.MemberId == memberId &&
                                                     (c.Status.Equals(PrizeConstants.STATUS_PLAN_STARTED + PrizeConstants.STATUS_PLAN_PAID) ||
                                                      c.Status.Equals(PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_PAID))
                                                     orderby c.EndDate descending
                                                     select c).FirstOrDefault();
            DateTime currentEndDate;
            if (myExistingPaidPlan != null)
            {
                currentEndDate = myExistingPaidPlan.EndDate.Value;
            }
            else
            {
                currentEndDate = PrizeCommonUtils.GetSystemDate();
            }

            List <MemberExercisePlan> myNotPaidPlans = (from c in db.MemberExercisePlans
                                                        where c.MemberId == memberId && (c.Status.EndsWith(PrizeConstants.STATUS_PLAN_NOT_PAID) || c.Status.EndsWith(PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT))
                                                        select c).ToList();

            foreach (MemberExercisePlan notPaidPlan in myNotPaidPlans)
            {
                IQueryable <MemberExercisePlanWeek> notPaidPlanWeeks = (from c in db.MemberExercisePlanWeeks
                                                                        where c.MemberExercisePlanId == notPaidPlan.Id
                                                                        select c);
                foreach (var week in notPaidPlanWeeks)
                {
                    MemberPlanWeekResult weekResult = (from c in db.MemberPlanWeekResults
                                                       where c.MemberExercisePlanWeekId == week.Id
                                                       select c).SingleOrDefault();
                    db.MemberExercisePlanWeeks.Remove(week);
                    db.MemberPlanWeekResults.Remove(weekResult);
                }
                notPaidPlan.Status = PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_PAYMENT_CANCELLED;

                List <MemberManualPayment> manualPayments = (from c in db.MemberManualPayments
                                                             where c.MemberExercisePlanId == notPaidPlan.Id && c.Status.StartsWith(PrizeConstants.STATUS_PLAN_MANUAL_PAYMENT_NOT_APPROVED)
                                                             select c).ToList();
                foreach (var notPaidRecord in manualPayments)
                {
                    db.MemberManualPayments.Remove(notPaidRecord);
                    db.SaveChanges();
                }
            }
            db.SaveChanges();

            DateTime startDate = PrizeCommonUtils.GetNextWeekStart(currentEndDate);
            DateTime endDate   = PrizeCommonUtils.GetWeekEnd(startDate);

            MemberExercisePlan myPlan = new MemberExercisePlan();
            myPlan.MemberId       = memberId;
            myPlan.ExercisePlanId = plan.Id;
            myPlan.StartDate      = startDate;
            myPlan.Status         = PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_NOT_PAID;              //Not paid
            db.MemberExercisePlans.Add(myPlan);
            db.SaveChanges();
            MemberPlanWeekResult myWeekResult;

            if (plan.IsTrialPlan != 1)
            {
                MemberExercisePlanWeek myPlanWeekOrientation = new MemberExercisePlanWeek();
                myPlanWeekOrientation.MemberExercisePlanId = myPlan.Id;
                myPlanWeekOrientation.ExercisePlanWeekId   = 0;
                myPlanWeekOrientation.MemberId             = memberId;
                myPlanWeekOrientation.StartDate            = startDate;
                myPlanWeekOrientation.EndDate = endDate;
                myPlanWeekOrientation.Status  = PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED;
                myPlanWeekOrientation.Week    = 0;
                db.MemberExercisePlanWeeks.Add(myPlanWeekOrientation);
                db.SaveChanges();

                myWeekResult          = new MemberPlanWeekResult();
                myWeekResult.MemberId = memberId;
                myWeekResult.MemberExercisePlanWeekId = myPlanWeekOrientation.Id;
                InitialiseWeekResult(ref myWeekResult);
                db.MemberPlanWeekResults.Add(myWeekResult);
                db.SaveChanges();
                myPlan.EndDate = endDate;
                startDate      = startDate.AddDays(7);
                endDate        = endDate.AddDays(7);
            }

            IList <PrizeExercisePlanWeek> planWeeks = plan.PrizeExercisePlanWeeks.OrderBy(s => s.StartWeek).ToList();
            foreach (PrizeExercisePlanWeek planWeek in planWeeks)
            {
                for (int i = planWeek.StartWeek; i <= planWeek.EndWeek; i++)
                {
                    MemberExercisePlanWeek myPlanWeek = new MemberExercisePlanWeek();
                    myPlanWeek.MemberExercisePlanId = myPlan.Id;
                    myPlanWeek.ExercisePlanWeekId   = planWeek.Id;
                    myPlanWeek.MemberId             = memberId;
                    myPlanWeek.StartDate            = startDate;
                    myPlanWeek.EndDate = endDate;
                    myPlanWeek.Status  = PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED;
                    myPlanWeek.Week    = i;
                    db.MemberExercisePlanWeeks.Add(myPlanWeek);
                    db.SaveChanges();

                    myWeekResult          = new MemberPlanWeekResult();
                    myWeekResult.MemberId = memberId;
                    myWeekResult.MemberExercisePlanWeekId = myPlanWeek.Id;
                    InitialiseWeekResult(ref myWeekResult);
                    db.MemberPlanWeekResults.Add(myWeekResult);
                    myPlan.EndDate = endDate;
                    db.SaveChanges();

                    startDate = startDate.AddDays(7);
                    endDate   = endDate.AddDays(7);
                }
            }

            //transaction.Complete();
            newMemberPlan = myPlan;
            prizePlan     = plan;

            return(newPlanId);
            //}
        }
        finally
        {
            db.Dispose();
        }
    }
    public static bool UpdateMemberPlans()
    {
        using (DIYPTEntities db = new DIYPTEntities())
        {
            try
            {
                db.Database.Connection.Open();

                DateTime today = PrizeCommonUtils.GetDayStart(PrizeCommonUtils.GetSystemDate());
                MemberExercisePlanWeek startingPlanWeek;
                String availableStatus = PrizeConstants.STATUS_PLAN_STARTED + PrizeConstants.STATUS_PLAN_PAID;
                IQueryable <MemberExercisePlan> plans = (from c in db.MemberExercisePlans
                                                         where c.Status.Equals(availableStatus)
                                                         orderby c.MemberId, c.Id
                                                         select c);

                foreach (MemberExercisePlan plan in plans)
                {
                    MemberExercisePlanWeek finishingPlanWeek = (from c in db.MemberExercisePlanWeeks
                                                                where c.MemberExercisePlanId == plan.Id && c.EndDate <= today &&
                                                                c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_STARTED)
                                                                orderby c.ExercisePlanWeekId
                                                                select c).FirstOrDefault();

                    if (finishingPlanWeek != null)
                    {
                        finishingPlanWeek.Status = PrizeConstants.STATUS_PLAN_WEEK_FINISHED;
                        startingPlanWeek         = (from c in db.MemberExercisePlanWeeks
                                                    where c.StartDate >= finishingPlanWeek.EndDate && c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED) &&
                                                    c.MemberExercisePlanId == plan.Id
                                                    orderby c.StartDate
                                                    select c).FirstOrDefault();
                        if (startingPlanWeek != null)
                        {
                            MemberPlanWeekResult finishingResult = (from c in db.MemberPlanWeekResults
                                                                    where c.MemberExercisePlanWeekId == finishingPlanWeek.Id
                                                                    select c).FirstOrDefault();

                            MemberPlanWeekResult startingResult = (from c in db.MemberPlanWeekResults
                                                                   where c.MemberExercisePlanWeekId == startingPlanWeek.Id
                                                                   select c).FirstOrDefault();
                            CopyWeekResult(ref startingResult, ref finishingResult);
                            startingPlanWeek.Status = PrizeConstants.STATUS_PLAN_WEEK_STARTED;
                        }
                        else
                        {
                            plan.Status = PrizeConstants.STATUS_PLAN_FINISHED + PrizeConstants.STATUS_PLAN_PAID;
                        }
                    }
                }

                availableStatus = PrizeConstants.STATUS_PLAN_NOT_STARTED + PrizeConstants.STATUS_PLAN_PAID;
                plans           = (from c in db.MemberExercisePlans
                                   where c.Status.Equals(availableStatus)
                                   orderby c.MemberId
                                   select c);

                foreach (MemberExercisePlan plan in plans)
                {
                    startingPlanWeek = (from c in db.MemberExercisePlanWeeks
                                        where c.StartDate <= today && c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_NOT_STARTED) &&
                                        c.MemberExercisePlanId == plan.Id
                                        orderby c.StartDate
                                        select c).FirstOrDefault();
                    if (startingPlanWeek != null)
                    {
                        MemberPlanWeekResult startingResult = (from c in db.MemberPlanWeekResults
                                                               where c.MemberExercisePlanWeekId == startingPlanWeek.Id
                                                               select c).FirstOrDefault();
                        MemberExercisePlanWeek finishedWeek = (from c in db.MemberExercisePlanWeeks
                                                               where c.EndDate < startingPlanWeek.StartDate && c.Status.Equals(PrizeConstants.STATUS_PLAN_WEEK_FINISHED)
                                                               select c).FirstOrDefault();
                        if (finishedWeek != null)
                        {
                            MemberPlanWeekResult finishingResult = (from c in db.MemberPlanWeekResults
                                                                    where c.MemberExercisePlanWeekId == finishedWeek.Id
                                                                    select c).FirstOrDefault();
                            CopyWeekResult(ref startingResult, ref finishingResult);
                        }

                        startingPlanWeek.Status = PrizeConstants.STATUS_PLAN_WEEK_STARTED;
                        plan.Status             = PrizeConstants.STATUS_PLAN_STARTED + PrizeConstants.STATUS_PLAN_PAID;
                    }
                }
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                PrizeLogs.SaveSystemErrorLog(0, 0, PrizeConstants.SystemErrorLevel.LevelSerious, typeof(PrizeMemberPlanManager).ToString(),
                                             "UpdateMemberPlans", e.Message, e.InnerException == null ? "" : e.InnerException.Message);
                return(false);
            }
            finally
            {
                db.Database.Connection.Close();
            }
        }
    }