public ActionResult SignUp(string email, string pwd)
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    Email       = email,
                    IsConfirmed = false
                };
                var confirmationService = new ConfirmationService();
                user.ConfirmationLink = confirmationService.GetUniqeConfirmationLink(HttpContext.Request.Url.Authority);
                user.Password         = PasswordHashing.HashString(pwd);
                using (var db = new Database())
                {
                    var superiorLink = Session["link"];
                    if (superiorLink != null)
                    {
                        user.SupperiorId = db.Users.FirstOrDefault(x => x.Link == superiorLink).UserId;
                    }
                    if (db.Users.Any(x => x.Email == email))
                    {
                        TempData["error-message"] = "Uživatel s tímto emailem již existuje";
                        return(RedirectToAction("Index", "Home"));
                    }

                    user.Link = Generators.GetRandomUniqueLink(7);

                    using (var dbContextTransaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            db.Users.Add(user);
                            db.SaveChanges();

                            confirmationService.SendConfirmationEmail(user.Email, user.ConfirmationLink);
                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult FacebookSignUp(string email, string fullname, string gender)
        {
            var user = new User()
            {
                Email       = email,
                IsConfirmed = false
            };
            var facebook = new FacebookIdentity()
            {
                Email   = email,
                Created = DateTime.Now,
                Gender  = gender
            };
            var name = fullname.Split(' ');

            if (!string.IsNullOrEmpty(name[0]))
            {
                facebook.FirstName = name[0];
            }
            if (!string.IsNullOrEmpty(name[1]))
            {
                facebook.LastName = name[1];
            }
            user.FacebookAccount = facebook;

            var confirmationService = new ConfirmationService();

            user.ConfirmationLink = confirmationService.GetUniqeConfirmationLink(HttpContext.Request.Url.Authority);
            var defaultPassword = Generators.GetRandomUniqueLink(10);

            user.Password = PasswordHashing.HashString(defaultPassword);
            using (var db = new Database())
            {
                var superiorLink = Session["link"];
                if (superiorLink != null)
                {
                    user.SupperiorId = db.Users.FirstOrDefault(x => x.Link == superiorLink).UserId;
                }
                if (db.Users.Any(x => x.Email == email))
                {
                    TempData["error-message"] = "Uživatel s tímto emailem již existuje";
                    return(RedirectToAction("Index", "Home"));
                }

                user.Link = Generators.GetRandomUniqueLink(7);

                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        db.Users.Add(user);
                        db.SaveChanges();

                        confirmationService.SendConfirmationEmail(user.Email, user.ConfirmationLink);
                        //TODO: odeslat email s defaultním heslem?? Nabídnout změnu hesla
                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }

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