public async Task<ActionResult> Register(RegisterViewModel model)
        {
            var repository = new ParseRepository(new WebCacheProvider(HttpContext.ApplicationInstance.Context));
            model.DeviceTypes =  repository.FindDeviceTypes();
            model.Countries = repository.FindCountriesNameAndId();
            if (ModelState.IsValid)
            {
                Exception logException = default(Exception);
                var userManager = new MyMentorUserManager(repository, Session);
                try
                {
                    model.CountryOfResidenceTitle = model.Countries[model.CountryOfResidence];


                    model.ContentTypeId = WorldIsRetriverFactory.GetWorldId(HttpContext, Session);
                    model.CurrencyId = (repository.FindResidenceById(model.CountryOfResidence)).CurrencyId;
                    await userManager.RegisterUser(model);

                    var parseUser = await userManager.Login(model.UserName, model.Password, Session);

                    Mailer.SendRegistrationSuccess(parseUser);
                    model.ShowSuccessMessage = true;
                    ViewBag.TeacherSuccessMessage = Strings.GetLocalizedString(Strings.RegistrationSuccessTeacher);
                    ViewBag.TeacherSuccessMessage = string.Format(ViewBag.TeacherSuccessMessage, model.FirstName);
                    ViewBag.StudentSuccessMessage = Strings.GetLocalizedString(Strings.RegistrationSuccessStudent);
                    ViewBag.StudentSuccessMessage = string.Format(ViewBag.StudentSuccessMessage, model.FirstName);
                }
                catch (ParseException ex)
                {
                    if (ex.Code == ParseException.ErrorCode.UsernameTaken)
                    {
                        ModelState.AddModelError("UserName", MyMentorResources.userExistsInTheSystem);
                    }
                    if (ex.Code == ParseException.ErrorCode.InvalidEmailAddress)
                    {
                        ModelState.AddModelError("UserName", MyMentorResources.illegalEmailAddress);
                    }
                    logException = ex;
                }
                catch (Exception ex)
                {
                    logException = ex;
                    mLogger.Log(LogLevel.Error, ex);

                    ModelState.AddModelError("_FORM", MyMentorResources.registrationGeneralError);
                }
                finally
                {
                    userManager.Dispose();
                }

                if (logException != null)
                {
                    await ParseLogger.Log("register new user", logException.ToString());
                }
            }
            else
            {
                var isCaptchaError = ModelState["CaptchaInputText"].Errors.Count > 0;
                ViewBag.IsCaptchaError = isCaptchaError;
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult UpdateStudent()
        {
            // await ParseUser.LogInAsync("*****@*****.**", "123456");
            ParseUser user = Session.GetLoggedInUser();
            StudentDetailsViewModel model = new StudentDetailsViewModel();
            ViewBag.IsAdmin = (user != null && !string.IsNullOrEmpty(Session.GetImpersonatingUserName())) || Session.GetLoggedInUserRoleName() == RoleNames.ADMINISTRATORS;

            if (user == null) return RedirectToAction("Login");

            var repository = new ParseRepository(new WebCacheProvider(HttpContext.ApplicationInstance.Context));
            var worldContentTypeRetriever = new WorldContentTypeRetriver(HttpContext, repository);
            var contentTypes =  worldContentTypeRetriever.GetContentTypes(user, Session.GetLoggedInUserRoleName());
            var currencies = repository.FindCurrencies();
            var uiLanguages =  repository.FindInterfaceLanguages();
            IEnumerable<UserGroup> groups = ( repository.FindGroups()).ToArray();
            IEnumerable<UserGroup> subGroups = ( repository.FindSubGroups()).ToArray();
            var sugLessonPublishingStatus = repository.FindUserPublishingStatus();
            var userStatuses = repository.FindUserStatus();

            model.DeviceTypes =  repository.FindDeviceTypes();
            model.Countries = repository.FindCountries();
            model.UserPrefferences.ContentTypes = contentTypes;
            model.UserPrefferences.Currencies = currencies;
            model.UserPrefferences.Languages = uiLanguages;
            model.Groups = groups;
            model.SubGroups = subGroups;
            model.SugLessonPublishingStatus = sugLessonPublishingStatus;
            model.UserStatusValues = userStatuses;

            model.FirstName = user.GetString("firstName_he_il");// user.Keys.Contains("firstName") ? user["firstName"] as string : string.Empty;
            model.LastName = user.GetString("lastName_he_il");// user.Keys.Contains("lastName") ? user["lastName"] as string : string.Empty;
            model.Email = user.Keys.Contains("email") ? user["email"] as string : string.Empty;
            model.Phone = user.Keys.Contains("phoneNumber") ? user["phoneNumber"] as string : string.Empty;
            model.Email = user.Keys.Contains("email") ? user["email"] as string : string.Empty;
            model.MailRecipientAddress = user.GetString("mailRecipientAddress");
            model.UserPrefferences.SelectedContentType = user.GetPointerObjectId("contentType");
                       
            model.UserPrefferences.SelectedCurrency = user.GetPointerObjectId("currency");
            model.UserPrefferences.SelectedLanguage = user.GetPointerObjectId("interfaceLanguage");
            
            model.CountryOfResidence = user.GetPointerObjectId("residenceCountry");

            model.SelectedDeviceType = user.Keys.Contains("deviceType") && (user["deviceType"] as ParseObject) != null ? (user["deviceType"] as ParseObject).FetchIfNeededAsync().Result.ObjectId : string.Empty;
            model.SelectedDeviceType = model.DeviceTypes.FirstOrDefault(deviceType => deviceType.Key.Split(new [] { '|' })[0] == model.SelectedDeviceType).Key;

            ViewBag.DeviceUnSupportedText =  Strings.GetLocalizedString(Strings.UnSupportedDevice);

            var userAdminData =  user.GetPointerObject<UserAdminData>("adminData");
            if (userAdminData != null)
            {
                model.AdminData.TCPTeacherCommission = userAdminData.TcpTeacherCommission.ToString("n2");
                model.AdminData.AgentUserName =userAdminData.Agent!=null? userAdminData.Agent.Username:string.Empty;
                model.AdminData.ACPAgentCommission = userAdminData.AcpTeacherCommission.ToString("n2");
                model.AdminData.STRCommissionRatio = userAdminData.StrCommissionRatio;
                model.AdminData.UserPublishingStatus = userAdminData.GetPointerObjectId("userPublishingStatus");
                model.AdminData.UserStatus = userAdminData.GetPointerObjectId("userStatus");
                model.AdminData.LockCountry = userAdminData.LockCountry;
                model.AdminData.LockCurrency = userAdminData.LockCurrency;
                model.AdminData.AdminRemarks = userAdminData.AdminRemarks;
                if (userAdminData.Group != null)
                {
                    var savedSelectedGroup = userAdminData.Group.ObjectId;
                    var selectedSubGroup = subGroups.SingleOrDefault(o => o.ObjectId == savedSelectedGroup);
                    var selectedGroup = groups.SingleOrDefault(o => o.ObjectId == savedSelectedGroup);
                    if (selectedSubGroup != null)
                    {
                        selectedGroup = groups.Single(o => o.ObjectId == selectedSubGroup.Parent.ObjectId);
                    }

                    model.AdminData.Group = selectedGroup != null ? selectedGroup.ObjectId : string.Empty;
                    model.AdminData.SubGroup = selectedSubGroup != null ? selectedSubGroup.ObjectId : string.Empty;
                }
            }

            model.Messages.CountryLocked = Strings.GetLocalizedString(Strings.CountryLocked);
            model.Messages.SugOsekLocked = Strings.GetLocalizedString(Strings.SugOsekLocked);
            model.Messages.CurrencyLocked = Strings.GetLocalizedString(Strings.CurrencyLocked);
            model.Messages.SugNirutLocked = Strings.GetLocalizedString(Strings.SugNirutLocked);
            model.Messages.AgentNotFound = Strings.GetLocalizedString(Strings.AgentNotFound);
            if (user.GetStatus() == UserStatusStrings.AppUser)
            {
                model.AppUserMessage = string.Format(MyMentorResources.appUserMoreDetails, user.GetFullName(Language.CurrentLanguageCode));
            }
            return View(model);
        }
        public ActionResult Register()
        {
            WorldIsRetriverFactory.GetWorldId(HttpContext, Session);

            var model = new RegisterViewModel();
            var repository = new ParseRepository(new WebCacheProvider(HttpContext.ApplicationInstance.Context));
            model.DeviceTypes =  repository.FindDeviceTypes();
            model.Countries = repository.FindCountriesNameAndId();

            ViewBag.DeviceUnSupportedText =  Strings.GetLocalizedString(Strings.UnSupportedDevice);
            return View(model);
        }