public ActionResult Index([Bind(Include = "language,strategy")] LanguageAndStrategyContener lanStr)
        {
            using (wordcontext = new WordsContext())
            {
                UserCl usercl = wordcontext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                if (usercl.languages.Where(x => x.id == lanStr.language.id).FirstOrDefault() == null)
                {
                    if (usercl.languages.ToList() == null)
                    {
                        usercl.languages = new List <Language>();
                    }
                    if (usercl.usersWords.ToList() == null)
                    {
                        usercl.usersWords = new List <UserWord>();
                    }
                    IQueryable <Word> languageWords = wordcontext.Words.Where(x => x.foreignLanguage.id == lanStr.language.id);
                    foreach (Word word in languageWords)
                    {
                        usercl.usersWords.Add(new UserWord()
                        {
                            lastTimeAccesed = DateTime.Now, levelOfKnowledge = 0, user = usercl, word = word
                        });
                    }
                    usercl.languages.Add(wordcontext.Languages.Where(x => x.id == lanStr.language.id).First());
                }
                usercl.settings.currentLangage           = usercl.languages.FirstOrDefault(x => x.id == lanStr.language.id);
                usercl.settings.numberOfWordsPerLearning = lanStr.strategy.id;
                wordcontext.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #2
0
        public ActionResult Index()
        {
            using (wordContext = new WordsContext())
            {
                bool isAuthenticated = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
                if (isAuthenticated)
                {
                    usercl = wordContext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                }

                return(View());
            }
        }
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        var usercl = new UserCl {
                            name = user.UserName
                        };
                        var userSettings = new UserSettings {
                            currentLangage = null, numberOfWordsPerLearning = 20
                        };
                        WordsContext wc = new WordsContext();

                        wc.Settings.Add(userSettings);
                        usercl.settings = userSettings;
                        wc.Users.Add(usercl);
                        wc.SaveChanges();
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
        // GET: ChooseLanguage

        public ActionResult Index()
        {
            using (wordcontext = new WordsContext())
            {
                usercl = wordcontext.Users.Where(x => x.name == User.Identity.Name).FirstOrDefault();
                List <Language>         languagesToChoose;
                List <LearningStrategy> strategiesToChoose = new List <LearningStrategy>();
                NormalLearningStrategy  s1 = new NormalLearningStrategy();
                NewWordsStrategy        s2 = new NewWordsStrategy();
                MediumLearningStrategy  s3 = new MediumLearningStrategy();
                strategiesToChoose.Add(s1);
                strategiesToChoose.Add(s2);
                strategiesToChoose.Add(s3);

                languagesToChoose  = wordcontext.Languages.Where((el) => el.id < 3).ToList();
                ViewBag.Strategies = strategiesToChoose;
                ViewBag.Languages  = languagesToChoose;

                return(View());
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var usercl = new UserCl {
                    name = user.UserName
                };
                var userSettings = new UserSettings {
                    currentLangage = null, numberOfWordsPerLearning = 20
                };
                WordsContext wc = new WordsContext();

                wc.Settings.Add(userSettings);
                usercl.settings = userSettings;
                wc.Users.Add(usercl);
                wc.SaveChanges();
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }