示例#1
0
        public async Task <ActionResult> ChangeGoal(ChangeGoalViewModel model)
        {
            // get current user id
            string userId = User.Identity.GetUserId();
            // change goal

            //check if user's pay
            ServiceResult result;
            bool          isPaid = await m_userService.IsPaid(userId);

            if (isPaid == true)
            {
                Session["isPaid"] = "true";
                result            = await m_classService.ChangeGoalAsync(userId, model.Class.Id, model.NumberOfDays);
            }
            else
            {
                result = await m_classService.ChangeGoalAsync(userId, model.Class.Id, UNPAID_USER_WORD_AMOUNT);

                //result = await m_classService.ChangeGoalAsync(userId, model.Class.Id, model.NumberOfDays);
                Session["isPaid"] = "false";
            }
            // Check result
            if (result == ServiceResult.Success)
            {
                return(RedirectToAction("ClassInfoAndRegister", "LearnWord", new { area = "galaxygate", classId = model.Class.Id }));
            }
            else
            {
                return(View("Error"));
            }
        }
示例#2
0
        public async Task <ServiceResult> DownGradeUserAsync(string userId)
        {
            try
            {
                ApplicationUser user = m_userRepository.FindEntity(x => x.Id == userId);
                if (user != null)
                {
                    //update user paid status
                    user.IsPaid = false;
                    await m_userRepository.UpdateAsync(user);

                    await m_userRepository.SaveChangesAsync();

                    var classes = await m_classService.GetRegisteredClassesAsync(userId); //get user registed class

                    foreach (Class c in classes)                                          // change goal all class
                    {
                        await m_classService.ChangeGoalAsync(userId, c.Id, HePa.Core.Helpers.Constraint.FreeUserLearnwordAmount.FREE_USER_LEARNWORD_AMOUNT);
                    }
                    return(ServiceResult.Success);
                }
                else
                {
                    return(ServiceResult.AddError("User is not found"));
                }
            }
            catch (Exception e)
            {
                return(ServiceResult.AddError(e.Data.ToString()));
            }
        }