コード例 #1
0
ファイル: CategoryBAL.cs プロジェクト: testsangu/AskMe
 public void DeleteQuestoinsCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.QuestionsCategories.Remove(category);
         _context.SaveChanges();
     }
 }
コード例 #2
0
ファイル: CategoryBAL.cs プロジェクト: testsangu/AskMe
 public void UpdateQuestionsCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
コード例 #3
0
ファイル: CategoryBAL.cs プロジェクト: testsangu/AskMe
 public void AddQuestionCategory(QuestionsCategory category)
 {
     using (var _context = new AskUsDbContext())
     {
         _context.QuestionsCategories.Add(category);
         _context.SaveChanges();
     }
 }
コード例 #4
0
 public QuestionsCategoryViewModel(QuestionsCategory model)
 {
     if (model != null)
     {
         Id        = model.Id;
         Name      = model.Name;
         Questions = model.Questions.Select(x => new IntellectualQuestionViewModel(x)).ToList();
     }
 }
コード例 #5
0
ファイル: CategoryBAL.cs プロジェクト: testsangu/AskMe
        public QuestionsCategory GetCategoryById(int id)
        {
            using (var _context = new AskUsDbContext())
            {
                QuestionsCategory Qcategory = _context.QuestionsCategories.Where(x => x.Id == id).FirstOrDefault();

                return(Qcategory);
            }
        }
コード例 #6
0
        //
        // GET: /QuestionsCategory/Edit/5
        public ActionResult Edit(int id)
        {
            var _categoryBAL             = new CategoryBAL();
            QuestionsCategory _QCategory = _categoryBAL.GetCategoryById(id);
            var model = new CategoryModel();

            model.Id          = _QCategory.Id;
            model.Name        = _QCategory.Name;
            model.IsActive    = _QCategory.IsActive;
            model.CreatedBy   = _QCategory.CreatedBy;
            model.CreatedDate = _QCategory.CreatedDate;

            return(View(model));
        }
コード例 #7
0
        public ActionResult Delete(int id, CategoryModel model)
        {
            try
            {
                CategoryBAL       _categoryBAL = new CategoryBAL();
                QuestionsCategory Qcategory    = _categoryBAL.GetCategoryById(id);
                Qcategory.Id          = model.Id;
                Qcategory.Name        = model.Name;
                Qcategory.UpdatedBy   = "Admin";
                Qcategory.UpdatedDate = DateTime.Now.ToUniversalTime();
                _categoryBAL.DeleteQuestoinsCategory(Qcategory);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #8
0
        public ActionResult Create(CategoryModel category)
        {
            try
            {
                // TODO: Add insert logic here
                CategoryBAL       _categoryBAL = new CategoryBAL();
                QuestionsCategory _QCategory   = new QuestionsCategory();
                _QCategory.Id          = category.Id;
                _QCategory.Name        = category.Name;
                _QCategory.CreatedBy   = "Admin";
                _QCategory.CreatedDate = DateTime.Now.ToUniversalTime();
                _categoryBAL.AddQuestionCategory(_QCategory);


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #9
0
ファイル: GameService.cs プロジェクト: Mityaechka/Int
        public async Task <ServiceResult> EditFirstRound(int gameId, FirstRoundEditViewModel model)
        {
            var game = await GetGameByPlayerRoles(gameId, PlayerRole.Creator);

            if (!game.IsSuccess)
            {
                return(Error(game.ErrorMessage));
            }
            FirstRound firstRound = game.Data.FirstRound;

            if (firstRound == null)
            {
                firstRound           = new FirstRound();
                game.Data.FirstRound = firstRound;
            }

            //if (firstRound.QuestionCosts != null)
            //    context.IntellectualQuestionCosts.RemoveRange(firstRound.QuestionCosts);
            if (firstRound.QuestionsCategories != null)
            {
                context.QuestionsCategorys.RemoveRange(firstRound.QuestionsCategories);
            }
            await context.SaveChangesAsync();

            //firstRound.QuestionCosts = model.QuestionCosts.Select(x =>
            //{
            //    var cost = new IntellectualQuestionCost { Index = index, Value = x };
            //    index++;
            //    return cost;
            //}).ToList();

            firstRound.QuestionsCategories = model.QuestionsCategories.Select(x =>
            {
                var questionIndex = 0;
                var category      = new QuestionsCategory
                {
                    Name      = x.Name,
                    Questions = x.Questions.Select(u =>
                    {
                        var answerIndex = 0;
                        var question    = new IntellectualQuestion
                        {
                            Index   = questionIndex,
                            Value   = u.Value,
                            Answers = u.Answers.Select(t =>
                            {
                                var answer = new IntellectualAnswer {
                                    Value = t, Index = answerIndex
                                };
                                answerIndex++;
                                return(answer);
                            }).ToList()
                        };
                        questionIndex++;
                        return(question);
                    }).ToList()
                };

                return(category);
            }).ToList();

            await context.SaveChangesAsync();

            return(Success());
        }