Beispiel #1
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (SurveyEntities db = new SurveyEntities())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Beispiel #2
0
 public ActionResult ResetPassword(string id)
 {
     //varify reset password link
     //rediecrt to reset password page
     //find account accociadted with the link
     //check the uniquecode from db
     using (SurveyEntities db = new SurveyEntities())
     {
         var user = db.Users.Where(a => a.ResetPassword == id).FirstOrDefault(); //find the account associated with this id
         if (user != null)                                                       //id is reset password code and we match it with the db reset pass code and if found user associated with this id
         {
             ResetPasswordModel mod = new ResetPasswordModel();
             mod.ResetCode = id; //so valide id when submit rest password form
             return(View(mod));  // here code for the user can see the rset password view
         }
         else
         {
             return(HttpNotFound());// error for invalid link
         }
     }
 }
Beispiel #3
0
        public void InsertTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                //get a question and answer
                tblAnswer   answer   = dc.tblAnswers.FirstOrDefault(a => a.Text == "Kelly Kapoor");
                tblQuestion question = dc.tblQuestions.FirstOrDefault(r => r.Text == "Who sprouts mung beans in their desk drawers?");

                //set properties
                tblResponse response = new tblResponse();
                response.Id         = Guid.NewGuid();
                response.QuestionId = question.Id;
                response.AnswerId   = answer.Id;

                dc.tblResponses.Add(response);

                int results = dc.SaveChanges();

                Assert.IsTrue(results > 0);
            }
        }
Beispiel #4
0
 public static List <Answer> Load()
 {
     try
     {
         List <Answer> answers = new List <Answer>();
         using (SurveyEntities dc = new SurveyEntities())
         {
             dc.tblAnswers
             .ToList()
             .ForEach(a => answers.Add(new Answer
             {
                 Id   = a.Id,
                 Text = a.Answer
             }));
         }
         return(answers);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #5
0
        //varify account
        public ActionResult VarifyAccount(string id)
        {
            bool Status = false;

            using (SurveyEntities db = new SurveyEntities())
            {
                db.Configuration.ValidateOnSaveEnabled = false;//avoid conform password not match save changes
                var v = db.Users.Where(a => a.ActivationCode == new Guid(id).ToString()).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVarify = true;
                    db.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invlid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer <SurveyEntities>(null);

                try
                {
                    using (var context = new SurveyEntities())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("SurveyEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
Beispiel #7
0
        public void LoadQuestions()
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //Foreach question in the database question q new question and add it to the question list
                    dc.tblQuestions.OrderBy(q => q.Text).ToList().ForEach(q => this.Add(new Question {
                        Id = q.Id, Text = q.Text
                    }));

                    foreach (Question q in this)
                    {
                        q.LoadAnswers();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static Question LoadByActivationCode(string code)
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                try
                {
                    var join =
                        from q in dc.tblQuestions
                        join a in dc.tblActivations
                        on q.Id equals a.QuestionId
                        where a.ActivationCode == code
                        select new { Id = q.Id };

                    Question question = LoadById(join.FirstOrDefault().Id);
                    question.Answers = AnswerManager.Load(question.Id);
                    return(LoadById(join.FirstOrDefault().Id));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Beispiel #9
0
        public int Update()
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //If the Id is set, get the result in the table where it matches
                    if (this.Id != Guid.Empty)
                    {
                        tblActivation activation = dc.tblActivations.Where(a => a.Id == this.Id).FirstOrDefault();

                        //If a row was retrieved, change
                        if (activation != null)
                        {
                            activation.ActivationCode = this.ActivationCode;
                            activation.EndDate        = this.EndDate;
                            activation.StartDate      = this.StartDate;
                            activation.QuestionId     = this.QuestionId;

                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Could not find Activation row with this ID");
                        }
                    }
                    else
                    {
                        throw new Exception("Id not set on Activation");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #10
0
        public void LoadQuestionById()
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //If the Id is set, get the result in the table where it matches
                    if (this.Id != Guid.Empty)
                    {
                        tblQuestion question = dc.tblQuestions.FirstOrDefault(q => q.Id == this.Id);

                        //If q row was retrieved, change
                        if (question != null)
                        {
                            this.Id   = question.Id;
                            this.Text = question.Text;

                            //Load the answers
                            this.LoadAnswers();
                        }
                        else
                        {
                            throw new Exception("Could not find Question row with this ID");
                        }
                    }
                    else
                    {
                        throw new Exception("Id not set on Question");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #11
0
        public static int Update(Activation activation, bool rollback = false)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    DbContextTransaction transaction = null;
                    if (rollback)
                    {
                        transaction = dc.Database.BeginTransaction();
                    }
                    tblActivation updaterow = dc.tblActivations.FirstOrDefault(q => q.Id == activation.Id);

                    if (updaterow != null)
                    {
                        updaterow.QuestionId     = activation.QuestionId;
                        updaterow.StartDate      = activation.StartDate;
                        updaterow.EndDate        = activation.EndDate;
                        updaterow.ActivationCode = activation.ActivationCode;
                    }
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                    if (rollback)
                    {
                        transaction.Rollback();
                    }
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #12
0
        public static Activation GetActivation(Guid questionId)
        {
            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    tblActivation row = new tblActivation();
                    row = dc.tblActivations.FirstOrDefault(q => q.QuestionId == questionId);
                    if (row == null)
                    {
                        return(null);
                    }
                    Activation activation = new Activation {
                        Id = row.Id, QuestionId = row.QuestionId, StartDate = row.StartDate, EndDate = row.EndDate, ActivationCode = row.ActivationCode
                    };

                    return(activation);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #13
0
 public static List <Question> Load()
 {
     try
     {
         List <Question> questions = new List <Question>();
         using (SurveyEntities dc = new SurveyEntities())
         {
             dc.tblQuestions
             .ToList()
             .ForEach(q => questions.Add(new Question
             {
                 Id        = q.Id,
                 Text      = q.Question,
                 Answers   = AnswerManager.Load(q.Id),
                 Activator = ActivationManager.GetActivation(q.Id)
             }));
         }
         return(questions);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #14
0
 // GET: Base
 public BaseController()
 {
     db = new SurveyEntities();
 }
Beispiel #15
0
 public SurveyEntities Init()
 {
     return dbContext ?? (dbContext = new SurveyEntities());
 }
Beispiel #16
0
 public ContractController(SurveyEntities _db, IPropertiesRepo repo)
 {
     this.db             = _db;
     this.PropertiesRepo = repo;
 }
Beispiel #17
0
 public UnitOfWork()
 {
     _context = new SurveyEntities();
 }
Beispiel #18
0
 //contructor
 public GenericType(SurveyEntities context)
 {
     Context = context;
     Dbset   = context.Set <TEntity>();
 }