示例#1
0
 public void ProcessRequest(HttpContext context)
 {
     this.Context = context;
     Context.Response.ContentType = "text/plain";
     //如果未登录
     if (!Extend.LoginState.Accounts.IsLogin)
     {
         Context.Response.Write(getBackJson(1, null, null));
         return;
     }
     //当前学员
     Song.Entities.Accounts st = Extend.LoginState.Accounts.CurrentUser;
     //当前课程
     Song.Entities.Course course = Business.Do <ICourse>().CourseSingle(couid);
     if (course == null)
     {
         Context.Response.Write(getBackJson(4, null, null));
         return;
     }
     //生成学员与课程的关联
     Song.Entities.Student_Course sc = new Entities.Student_Course();
     //是否试用
     if (isTry)
     {
         Try(course, st);
     }
     //如果免费购买
     if (!isTry && isFree)
     {
         FreeBuy(course, st);
     }
     //如果不是免费课程,花钱买课程
     if (!isTry && !isFree)
     {
         Buy(course, st);
     }
 }
示例#2
0
 /// <summary>
 /// 免费购买
 /// </summary>
 /// <param name="course"></param>
 /// <param name="st"></param>
 private void FreeBuy(Song.Entities.Course course, Song.Entities.Accounts st)
 {
     //如果不是免费课程
     if (!course.Cou_IsFree)
     {
         //当课程不是免费的,直接退出
         Context.Response.Write(getBackJson(7, null, null));
         return;
     }
     else
     {
         //生成学员与课程的关联
         Song.Entities.Student_Course sc = Business.Do <ICourse>().StudyCourse(st.Ac_ID, couid);
         if (sc == null)
         {
             sc = new Entities.Student_Course();
         }
         sc.Cou_ID        = couid;
         sc.Ac_ID         = st.Ac_ID;
         sc.Stc_StartTime = DateTime.Now;
         sc.Stc_EndTime   = DateTime.Now.AddYears(101);
         sc.Stc_IsFree    = true;
         sc.Stc_IsTry     = false;
         try
         {
             Business.Do <ICourse>().Buy(sc);
             Extend.LoginState.Accounts.Course(course);
             Context.Response.Write(getBackJson(0, sc, null));
             return;
         }
         catch (Exception ex)
         {
             Context.Response.Write(getBackJson(6, null, ex));
             return;
         }
     }
 }