コード例 #1
0
 public PersonalQuizModel(PersonalQuiz quiz)
 {
     WordsThatDescribesMe            = quiz.WordsThatDescribesMe;
     ChoiceBetweenMoneyLoveHappiness = quiz.ChoiceBetweenMoneyLoveHappiness;
     AttractiveInPartner             = quiz.AttractiveInPartner;
     Id = quiz.Id;
 }
コード例 #2
0
 public int Add(PersonalQuiz quiz)
 {
     try
     {
         using (_tholaUmuntuContext)
         {
             _tholaUmuntuContext.PersonalQuizzes.Add(quiz);
             return(_tholaUmuntuContext.SaveChanges());
         }
     }
     catch (DbException e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
コード例 #3
0
        public bool Update(PersonalQuiz quiz)
        {
            try
            {
                using (_tholaUmuntuContext)
                {
                    var result = _tholaUmuntuContext.PersonalQuizzes.SingleOrDefault(b => b.Id == quiz.Id);
                    if (result != null)
                    {
                        result = quiz;
                        _tholaUmuntuContext.PersonalQuizzes.AddOrUpdate(result);
                        return(_tholaUmuntuContext.SaveChanges() > 0);
                    }
                }
            }
            catch (DbException e)
            {
                Console.WriteLine(e.Message);
                throw;
            }

            return(false);
        }
コード例 #4
0
        public ActionResult AddPersonalQuizToProfile(UserProfileModel model)
        {
            var choice = Choice.Happiness;

            Id = Convert.ToInt32(Session["UserId"]);
            var currentUser = _userRepository.GetUserById(model.User.Id);

            switch (Convert.ToInt32(model.Quiz.Choice))
            {
            case 1:
                choice = Choice.Money;
                break;

            case 2:
                choice = Choice.Love;
                break;

            case 3:
                choice = Choice.Happiness;
                break;
            }
            var quiz = new PersonalQuiz
            {
                AttractiveInPartner             = model.Quiz.AttractiveInPartner,
                WordsThatDescribesMe            = model.Quiz.WordsThatDescribesMe,
                ChoiceBetweenMoneyLoveHappiness = choice,
                UserId     = currentUser.Id,
                CreatedAt  = DateTime.Now,
                ModifiedAt = DateTime.Now,
            };

            try
            {
                var transactionPassed = false;

                if (model.Quiz.Id > 0)
                {
                    quiz.Id = model.Quiz.Id;

                    if (_personalQuizRepository.Update(quiz))
                    {
                        transactionPassed = true;
                    }
                }
                else
                {
                    var id = _personalQuizRepository.Add(quiz);

                    if (id > 0)
                    {
                        transactionPassed = true;
                    }
                }

                if (transactionPassed)
                {
                    var profile = _profileRepository.GetProfileByUserId(Id);
                    profile.QuizId       = quiz.Id;
                    profile.Horoscope    = model.Horoscope;
                    profile.LoveLanguage = model.LoveLanguage;

                    _profileRepository.UpdateUserProfile(profile);
                    ViewBag.Success = true;

                    return(RedirectToAction("Index"));
                }

                ViewBag.Success = false;

                return(RedirectToAction("Index"));
            }
            catch (DbException e)
            {
                Console.WriteLine(e);
                throw;
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View("Index"));

                return(Json(new { Error = e.Message, JsonRequestBehavior.AllowGet }));
            }
        }
コード例 #5
0
 public bool Update(PersonalQuiz quiz)
 {
     return(_quizRepository.Update(quiz));
 }
コード例 #6
0
 public int Add(PersonalQuiz quiz)
 {
     return(_quizRepository.Add(quiz));
 }