Beispiel #1
0
        public ActionResult SearchQuestionList(QuestionSelectSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Question").ToInputLogString());

            try
            {
                if (ModelState.IsValid)
                {
                    _questionGroupFacade = new QuestionGroupFacade();
                    var model = new QuestionGroupEditViewModel();
                    model.SearchFilter = searchFilter;

                    model.QuestionList = _questionGroupFacade.GetQuestionList(model.SearchFilter);
                    ViewBag.PageSize   = model.SearchFilter.PageSize;

                    return(PartialView("~/Views/QuestionGroup/_QuestionList.cshtml", model));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Question").ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
        public ActionResult ViewQuestionGroup(int id)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("View Question Group").Add("QuestionGroupId", id).ToSuccessLogString());

            try
            {
                _questionGroupFacade = new QuestionGroupFacade();
                var questionGroup = _questionGroupFacade.GetQuestionGroupById(id);
                var questionList  = _questionGroupFacade.GetQuestionList(id);

                var model = new ViewQuestionGroupModel();
                model.Name        = questionGroup.QuestionGroupName;
                model.Description = questionGroup.Description;
                model.ProductName = questionGroup.ProductName;
                model.Status      = (questionGroup.Status ?? false) ? "Active" : "Inactive";
                model.CreateUser  = questionGroup.CreateUserName;
                model.UpdateUser  = questionGroup.UpdateUserName;
                model.CreateDate  = DateUtil.ToStringAsDateTime(questionGroup.CreateDate);
                model.UpdateDate  = DateUtil.ToStringAsDateTime(questionGroup.UpdateDate);

                model.QuestionList = questionList.Select(x => new ViewQuestionModel()
                {
                    SeqNo        = x.SeqNo,
                    QuestionName = x.QuestionName,
                }).ToList();

                return(View(model));
            }
            catch (Exception ex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("View Question Group").ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Beispiel #3
0
        public ActionResult SearchQuestion(BootstrapParameters parameters, string questionName, string questionIdList)
        {
            if (ModelState.IsValid)
            {
                _questionGroupFacade = new QuestionGroupFacade();
                var questionGroupVM = new QuestionGroupViewModel();

                var totalCount = 0;

                List <QuestionItemEntity> list = _questionGroupFacade.SearchQuestionGroupQuestion(parameters.offset, parameters.limit, questionName, questionIdList, ref totalCount);

                return(Json(new BootstrapTableResult()
                {
                    total = totalCount,
                    rows = list.Select(item => new
                    {
                        id = item.QuestionId,
                        //                        action = string.Format("<a onClick='editQuestion({0})' class='btnEdit'><i class='fa fa-edit'></i></a>", item.QuestionId),
                        question_name = item.QuestionName,
                        status = item.Status.HasValue ? item.Status.Value ? "Active" : "Inactive" : "Inactive",
                        update_name = string.IsNullOrEmpty(item.UpdateUserName.FullName) ? item.CreateUserName.FullName : item.UpdateUserName.FullName,
                        update_date = !item.UpdateDate.HasValue ? DateUtil.ToStringAsDateTime(item.CreateDate) : DateUtil.ToStringAsDateTime(item.UpdateDate)
                    }).ToList()
                }));
            }

            return(Json(new
            {
                Valid = false,
                Error = string.Empty
            }));
        }
Beispiel #4
0
        public ActionResult SearchQuestionGroupList(QuestionGroupSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search QuestionGroup").ToInputLogString());

            try
            {
                if (ModelState.IsValid)
                {
                    _questionGroupFacade = new QuestionGroupFacade();
                    QuestionGroupViewModel questionGroupVM = new QuestionGroupViewModel();
                    questionGroupVM.SearchFilter      = searchFilter;
                    questionGroupVM.QuestionGroupList = _questionGroupFacade.GetQuestionGroupList(questionGroupVM.SearchFilter);
                    ViewBag.PageSize = questionGroupVM.SearchFilter.PageSize;
                    return(PartialView("~/Views/QuestionGroup/_QuestionGroupList.cshtml", questionGroupVM));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search QuestionGroup").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Beispiel #5
0
        public ActionResult Edit(int?questionGroupId)
        {
            if (questionGroupId.HasValue)
            {
                var questionGroupVM = new QuestionGroupEditViewModel();
                _questionGroupFacade = new QuestionGroupFacade();

                //get area section
                QuestionGroupItemEntity questionGroupItemEntity = _questionGroupFacade.GetQuestionGroupById(questionGroupId.Value);
                questionGroupVM.QuestionGroupId          = questionGroupItemEntity.QuestionGroupId;
                questionGroupVM.QuestionGroupName        = questionGroupItemEntity.QuestionGroupName;
                questionGroupVM.QuestionGroupProductName = questionGroupItemEntity.QuestionGroupProduct;
                questionGroupVM.QuestionGroupProductId   = questionGroupItemEntity.QuestionGroupProductId;
                questionGroupVM.CreateUserName           = questionGroupItemEntity.CreateUserName != null ? questionGroupItemEntity.CreateUserName.FullName : "";
                questionGroupVM.UpdateUserName           = questionGroupItemEntity.UpdateUserName != null ? questionGroupItemEntity.UpdateUserName.FullName : "";
                questionGroupVM.DisplayCreateDate        = DateUtil.ToStringAsDateTime(questionGroupItemEntity.CreateDate);
                questionGroupVM.DisplayUpdateDate        = DateUtil.ToStringAsDateTime(questionGroupItemEntity.UpdateDate);
                questionGroupVM.QuestionGroupDescription = questionGroupItemEntity.Description;

                questionGroupVM.Status     = questionGroupItemEntity.Status;
                questionGroupVM.StatusList = new List <SelectListItem>();

                questionGroupVM.StatusList.Add(new SelectListItem()
                {
                    Text = "Active", Value = "true"
                });
                questionGroupVM.StatusList.Add(new SelectListItem()
                {
                    Text = "Inactive", Value = "false"
                });

                questionGroupVM.QuestionGroupInQuestionSearchFilter = new QuestionGroupInQuestionSearchFilter()
                {
                    QuestionGroupId = null,
                    PageNo          = 1,
                    PageSize        = 15,
                    SortField       = "GroupName",
                    SortOrder       = "ASC"
                };

                questionGroupVM.SearchFilter = new QuestionSelectSearchFilter()
                {
                    QuestionName   = string.Empty,
                    QuestionIdList = string.Empty,
                    PageNo         = 1,
                    PageSize       = 15,
                    SortField      = "QuestionName",
                    SortOrder      = "ASC"
                };

                //get sub area section
                return(View(questionGroupVM));
            }

            return(View("Create"));
        }
Beispiel #6
0
        public JsonResult Autocomplete(string Prefix)
        {
            _questionGroupFacade = new QuestionGroupFacade();
            var totalCount = 0;
            List <QuestionGroupProductEntity> list = _questionGroupFacade.GetProductList(Prefix, ref totalCount);

            return(Json(list.Select(item => new
            {
                Product = item.Product,
                ProductGroup = item.ProductGroup
            })));
        }
Beispiel #7
0
        public ActionResult SaveQuestionGroup(QuestionGroupSaveViewModel questionGroupSaveVM, string idQuestions)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Save Group Question").ToInputLogString());
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(questionGroupSaveVM.QuestionGroupProductIds))
                    {
                        ModelState.AddModelError("QuestionGroupProductIds", "กรุณาระบุ Product อย่างน้อย 1 รายการ");

                        return(Json(new
                        {
                            Valid = false,
                            Error = string.Empty,
                            Errors = GetModelValidationErrors()
                        }));
                    }

                    _questionGroupFacade = new QuestionGroupFacade();

                    var productIds = questionGroupSaveVM.QuestionGroupProductIds.Split(',').Select(Int32.Parse).ToList();
                    var questionGroupForSaveList = new List <QuestionGroupItemEntity>();

                    var name = questionGroupSaveVM.QuestionGroupName.NullSafeTrim();
                    var desc = questionGroupSaveVM.Description.NullSafeTrim();

                    var duplicateQuestionGroups = _questionGroupFacade.GetQuestionGroupDuplicates(productIds, name, questionGroupSaveVM.QuestionGroupId);

                    if (duplicateQuestionGroups.Count > 0)
                    {
                        var productNames = string.Join(",", duplicateQuestionGroups.Select(x => x.ProductName).ToList());
                        ModelState.AddModelError("QuestionGroupProductIds", string.Format(CultureInfo.InvariantCulture, "ชื่อกลุ่มคำถามที่บันทึก มีอยู่แล้วใน Product '{0}'", productNames));

                        return(Json(new
                        {
                            Valid = false,
                            Error = string.Empty,
                            Errors = GetModelValidationErrors()
                        }));
                    }

                    foreach (var productId in productIds)
                    {
                        var item = new QuestionGroupItemEntity
                        {
                            QuestionGroupId        = questionGroupSaveVM.QuestionGroupId,
                            QuestionGroupName      = name,
                            QuestionGroupProductId = productId,
                            Description            = desc,
                            Status = questionGroupSaveVM.Status,
                            UserId = UserInfo.UserId
                        };

                        questionGroupForSaveList.Add(item);
                    }

                    foreach (var questionGroup in questionGroupForSaveList)
                    {
                        _questionGroupFacade.SaveQuestionGroup(questionGroup, idQuestions);
                    }

                    return(Json(new { is_success = true, message = "บันทึก Group Question สำเร็จ" }));
                }

                return(Json(new
                {
                    is_success = false,
                    message = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save Group Question").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }