Ejemplo n.º 1
0
        public async Task <ActionResult> ConfirmEmail(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }
            var result = await UserManager.ConfirmEmailAsync(userId, code);

            var db = new EnglishLearningEntities();

            Models.User user = new User();
            //TODO: try catch может помешать при отлавливании ошибок
            try
            {
                user.IdentityId      = userId;
                user.Level           = "Beginner";
                user.ObjectiveLevel  = "Beginner";
                user.LvlListening    = "Beginner";
                user.LvlReading      = "Beginner";
                user.LvlWriting      = "Beginner";
                user.ObjLvlListening = "Beginner";
                user.ObjLvlReading   = "Beginner";
                user.ObjLvlWriting   = "Beginner";
                user.Tested          = false;
                db.User.Add(user);
                db.SaveChanges();
            }
            catch
            {
                ApplicationUser userToDelete = UserManager.FindById(userId);
                var             login        = UserManager.DeleteAsync(userToDelete);
                return(View("Error"));
            }
            return(View(result.Succeeded ? "ConfirmEmail" : "Error"));
        }
Ejemplo n.º 2
0
        private ActionResult RedirectToLocal(string returnUrl, string userId = "")
        {
            var db = new EnglishLearningEntities();

            if (!string.IsNullOrWhiteSpace(userId))
            {
                //string temp = User.Identity.GetUserId();
                bool tested;
                if (db.User.Where(x => x.IdentityId == userId).Count() > 0)
                {
                    tested = db.User.Where(x => x.IdentityId == userId).Select(x => x.Tested).First();
                }
                else
                {
                    tested = true;
                }

                if (!tested)
                {
                    return(RedirectToAction("Test", "Test", new { id = db.Test.Where(x => x.Name == "Загальний рівень знань").Select(x => x.TestId).First() }));
                }
            }

            if (db.User.Where(x => x.IdentityId == userId).Count() > 0)
            {
                var tempDate     = DateTime.Now.Date;
                var id           = db.User.Where(x => x.IdentityId == userId).Select(x => x.UserId).First();
                var notification = (from t in db.UserELTask.Include("ELTask")
                                    where t.Done == false && tempDate >= DbFunctions.TruncateTime(t.Date.Value) && t.UserId == id
                                    select t.ELTask.Name).ToArray();
                HttpCookie cookie = new HttpCookie("Notification", string.Join("; ", notification));
                Response.AppendCookie(cookie);
            }

            if (Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            return(RedirectToAction("Index", "Home"));
        }