Beispiel #1
0
        public bool CheckDuplicateMappProduct(MappingProductTypeItemEntity mappingItemEntity)
        {
            var isDuplicate = false;

            if (!mappingItemEntity.MapProductId.HasValue)
            {
                //add mode
                if (mappingItemEntity.CampaignServiceId.HasValue)
                {
                    isDuplicate =
                        _context.TB_M_MAP_PRODUCT.Any(
                            q =>
                            q.PRODUCT_ID == mappingItemEntity.ProductId &&
                            q.CAMPAIGNSERVICE_ID == mappingItemEntity.CampaignServiceId.Value &&
                            q.AREA_ID == mappingItemEntity.AreaId &&
                            q.SUBAREA_ID == mappingItemEntity.SubAreaId &&
                            q.TYPE_ID == mappingItemEntity.TypeId);
                }
                else
                {
                    isDuplicate =
                        _context.TB_M_MAP_PRODUCT.Any(
                            q =>
                            q.PRODUCT_ID == mappingItemEntity.ProductId &&
                            q.CAMPAIGNSERVICE_ID == null &&
                            q.AREA_ID == mappingItemEntity.AreaId &&
                            q.SUBAREA_ID == mappingItemEntity.SubAreaId &&
                            q.TYPE_ID == mappingItemEntity.TypeId);
                }
            }
            else
            {
                //edit mode
                if (mappingItemEntity.CampaignServiceId.HasValue)
                {
                    isDuplicate =
                        _context.TB_M_MAP_PRODUCT.Any(
                            q =>
                            q.MAP_PRODUCT_ID != mappingItemEntity.MapProductId.Value &&
                            q.PRODUCT_ID == mappingItemEntity.ProductId &&
                            q.CAMPAIGNSERVICE_ID == mappingItemEntity.CampaignServiceId.Value &&
                            q.AREA_ID == mappingItemEntity.AreaId &&
                            q.SUBAREA_ID == mappingItemEntity.SubAreaId &&
                            q.TYPE_ID == mappingItemEntity.TypeId);
                }
                else
                {
                    isDuplicate =
                        _context.TB_M_MAP_PRODUCT.Any(
                            q =>
                            q.MAP_PRODUCT_ID != mappingItemEntity.MapProductId.Value &&
                            q.PRODUCT_ID == mappingItemEntity.ProductId &&
                            q.CAMPAIGNSERVICE_ID == null &&
                            q.AREA_ID == mappingItemEntity.AreaId &&
                            q.SUBAREA_ID == mappingItemEntity.SubAreaId &&
                            q.TYPE_ID == mappingItemEntity.TypeId);
                }
            }
            return(isDuplicate);
        }
 public bool CheckDuplicateMappProduct(MappingProductTypeItemEntity mappingItemEntity)
 {
     _mappingProductTypeDataAccess = new MappingProductTypeDataAccess(_context);
     return(_mappingProductTypeDataAccess.CheckDuplicateMappProduct(mappingItemEntity));
 }
 public bool SaveMapProduct(MappingProductTypeItemEntity mappingItemEntity, List <ProductQuestionGroupItemEntity> productQuestionEntityList)
 {
     _mappingProductTypeDataAccess = new MappingProductTypeDataAccess(_context);
     return(_mappingProductTypeDataAccess.SaveMapProduct(mappingItemEntity, productQuestionEntityList));
 }
Beispiel #4
0
        public bool SaveMapProduct(MappingProductTypeItemEntity mappingItemEntity, List <ProductQuestionGroupItemEntity> productQuestionEntityList)
        {
            _context.Configuration.AutoDetectChangesEnabled = false;

            try
            {
                var isEdit = mappingItemEntity.MapProductId.HasValue;
                TB_M_MAP_PRODUCT mapProduct;

                if (!isEdit)
                {
                    //add mode
                    mapProduct = new TB_M_MAP_PRODUCT();
                }
                else
                {
                    //edit mode
                    mapProduct = _context.TB_M_MAP_PRODUCT.SingleOrDefault(m => m.MAP_PRODUCT_ID == mappingItemEntity.MapProductId.Value);
                    if (mapProduct == null)
                    {
                        Logger.ErrorFormat("MAP_PRODUCT ID: {0} does not exist", mappingItemEntity.AreaId);
                        return(false);
                    }
                }

                mapProduct.PRODUCT_ID            = mappingItemEntity.ProductId;
                mapProduct.CAMPAIGNSERVICE_ID    = mappingItemEntity.CampaignServiceId;
                mapProduct.AREA_ID               = mappingItemEntity.AreaId;
                mapProduct.SUBAREA_ID            = mappingItemEntity.SubAreaId;
                mapProduct.TYPE_ID               = mappingItemEntity.TypeId;
                mapProduct.DEFAULT_OWNER_USER_ID = mappingItemEntity.OwnerUserId;
                mapProduct.SR_PAGE_ID            = mappingItemEntity.SrPageId;
                mapProduct.MAP_PRODUCT_IS_VERIFY = mappingItemEntity.IsVerify;
                mapProduct.MAP_PRODUCT_IS_ACTIVE = mappingItemEntity.IsActive;
                mapProduct.UPDATE_USER           = mappingItemEntity.UserId;
                mapProduct.UPDATE_DATE           = DateTime.Now;

                if (!isEdit)
                {
                    //add
                    mapProduct.CREATE_USER = mappingItemEntity.UserId;
                    mapProduct.CREATE_DATE = DateTime.Now;
                    _context.TB_M_MAP_PRODUCT.Add(mapProduct);
                    Save();

                    //save map product question group
                    if (productQuestionEntityList.Any())
                    {
                        foreach (var productQuestionEntity in productQuestionEntityList)
                        {
                            var mapProductQuestionGroup = new TB_M_MAP_PRODUCT_QUESTIONGROUP();
                            mapProductQuestionGroup.MAP_PRODUCT_ID      = mapProduct.MAP_PRODUCT_ID;
                            mapProductQuestionGroup.QUESTIONGROUP_ID    = Convert.ToInt32(productQuestionEntity.id, CultureInfo.InvariantCulture);
                            mapProductQuestionGroup.REQUIRE_AMOUNT_PASS = Convert.ToInt32(productQuestionEntity.pass_value, CultureInfo.InvariantCulture);
                            mapProductQuestionGroup.SEQ_NO = Convert.ToInt32(productQuestionEntity.seq, CultureInfo.InvariantCulture);
                            _context.TB_M_MAP_PRODUCT_QUESTIONGROUP.Add(mapProductQuestionGroup);
                            Save();
                        }
                    }
                }
                else
                {
                    SetEntryStateModified(mapProduct);

                    //delete map product question group
                    var mapProductQuestionList = _context.TB_M_MAP_PRODUCT_QUESTIONGROUP.Where(q => q.MAP_PRODUCT_ID == mappingItemEntity.MapProductId);
                    foreach (var mapProductQuestionItem in mapProductQuestionList)
                    {
                        _context.TB_M_MAP_PRODUCT_QUESTIONGROUP.Remove(mapProductQuestionItem);
                    }
                    this.Save();

                    //update map product question group
                    if (productQuestionEntityList.Any())
                    {
                        foreach (var productQuestionEntity in productQuestionEntityList)
                        {
                            var mapProductQuestionGroup = new TB_M_MAP_PRODUCT_QUESTIONGROUP();
                            mapProductQuestionGroup.MAP_PRODUCT_ID      = mapProduct.MAP_PRODUCT_ID;
                            mapProductQuestionGroup.QUESTIONGROUP_ID    = Convert.ToInt32(productQuestionEntity.id, CultureInfo.InvariantCulture);
                            mapProductQuestionGroup.REQUIRE_AMOUNT_PASS = Convert.ToInt32(productQuestionEntity.pass_value, CultureInfo.InvariantCulture);
                            mapProductQuestionGroup.SEQ_NO = Convert.ToInt32(productQuestionEntity.seq, CultureInfo.InvariantCulture);
                            _context.TB_M_MAP_PRODUCT_QUESTIONGROUP.Add(mapProductQuestionGroup);
                            Save();
                        }
                    }
                }

                Save();
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                return(false);
            }
            finally
            {
                _context.Configuration.AutoDetectChangesEnabled = true;
            }
        }
        public ActionResult Save(MappingProductTypeSaveModel model)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Mapping Product Save").ToInputLogString());
            try
            {
                if (ModelState.IsValid)
                {
                    MappingProductTypeItemEntity mappingProductTypeItemEntity = new MappingProductTypeItemEntity()
                    {
                        MapProductId      = model.MapProductId,
                        ProductId         = model.ProductId,
                        CampaignServiceId = model.CampaignServiceId,
                        AreaId            = model.AreaId,
                        SubAreaId         = model.SubAreaId,
                        TypeId            = model.TypeId,
                        OwnerBranchId     = model.OwnerUserId,
                        OwnerUserId       = model.OwnerSrId,
                        SrPageId          = model.SrPageId,
                        IsVerify          = model.IsVerify,
                        IsActive          = model.IsActive,
                        UserId            = UserInfo.UserId
                    };

                    _mappingProductTypeFacade = new MappingProductTypeFacade();

                    //check duplicate mapping product
                    var isDuplicate = _mappingProductTypeFacade.CheckDuplicateMappProduct(mappingProductTypeItemEntity);
                    if (isDuplicate)
                    {
                        return(Json(new
                        {
                            is_success = false,
                            message = "Map product ซ้ำ ไม่สามารบันทึกได้"
                        }));
                    }

                    var list = new JavaScriptSerializer().Deserialize <ProductQuestionGroupItemEntity[]>(model.QuestionGroupList);
                    List <ProductQuestionGroupItemEntity> productQuestionGroupItemEntityList = new List <ProductQuestionGroupItemEntity>();

                    foreach (var item in list)
                    {
                        ProductQuestionGroupItemEntity productQuestionGroupItemEntity = new ProductQuestionGroupItemEntity
                        {
                            id         = item.id,
                            pass_value = item.pass_value,
                            seq        = item.seq
                        };

                        productQuestionGroupItemEntityList.Add(productQuestionGroupItemEntity);
                    }

                    var isSuccess = _mappingProductTypeFacade.SaveMapProduct(mappingProductTypeItemEntity,

                                                                             productQuestionGroupItemEntityList);
                    return(isSuccess
                        ? Json(new { is_success = true, message = "บันทึก Map Product Question สำเร็จ" })
                        : Json(new { is_success = false, message = "บันทึก Map Product Question ไม่สำเร็จ" }));
                }

                return(Json(new
                {
                    is_success = false,
                    message = string.Empty
                }));
            }
            catch (Exception ex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Mapping Product Save").ToFailLogString());
                return(Json(new { is_success = false, message = string.Format(CultureInfo.InvariantCulture, "Error : {0}", ex.Message) }));
            }
        }
        public ActionResult Edit(int?mapProductId)
        {
            if (mapProductId.HasValue)
            {
                var model = new MappingProductTypeEditModel();

                _srPageFacade = new SrPageFacade();

                var srPageList = _srPageFacade.GetSrPageList();
                model.SrPageList = srPageList.Select(item => new SelectListItem()
                {
                    Text  = item.SrPageName,
                    Value = item.SrPageId.ToString(CultureInfo.InvariantCulture)
                }).ToList();

                _mappingProductTypeFacade = new MappingProductTypeFacade();
                MappingProductTypeItemEntity mapItemEntity = _mappingProductTypeFacade.GetMappingById(mapProductId.Value);
                model.MapProductId        = mapItemEntity.MapProductId;
                model.ProductGroupId      = mapItemEntity.ProductGroupId;
                model.ProductGroupName    = mapItemEntity.ProductGroupName;
                model.ProductId           = mapItemEntity.ProductId;
                model.ProductName         = mapItemEntity.ProductName;
                model.CampaignServiceId   = mapItemEntity.CampaignServiceId;
                model.CampaignServiceName = mapItemEntity.CampaignName;
                model.AreaId          = mapItemEntity.AreaId;
                model.AreaName        = mapItemEntity.AreaName;
                model.SubAreaId       = mapItemEntity.SubAreaId;
                model.SubAreaName     = mapItemEntity.SubAreaName;
                model.TypeId          = mapItemEntity.TypeId;
                model.TypeName        = mapItemEntity.TypeName;
                model.OwnerBranchId   = mapItemEntity.OwnerBranchId;
                model.OwnerBranchName = mapItemEntity.OwnerBranchName;
                model.OwnerSrId       = mapItemEntity.OwnerUserId;
                model.OwnerSrName     = mapItemEntity.OwnerSrName;
                model.CreateUser      = mapItemEntity.CreateUser != null ? mapItemEntity.CreateUser.FullName : "";
                model.UpdateUser      = mapItemEntity.UpdateUser != null ? mapItemEntity.UpdateUser.FullName : "";
                model.CreateDate      = DateUtil.ToStringAsDateTime(mapItemEntity.CreateDate);
                model.UpdateDate      = DateUtil.ToStringAsDateTime(mapItemEntity.UpdateDate);

                model.VerifyList = new List <SelectListItem>();
                if (mapItemEntity.IsVerify)
                {
                    //verify
                    model.VerifyList.Add(new SelectListItem()
                    {
                        Text = "Yes", Value = "true", Selected = true
                    });
                    model.VerifyList.Add(new SelectListItem()
                    {
                        Text = "No", Value = "false"
                    });
                }
                else
                {
                    model.VerifyList.Add(new SelectListItem()
                    {
                        Text = "Yes", Value = "true"
                    });
                    model.VerifyList.Add(new SelectListItem()
                    {
                        Text = "No", Value = "false", Selected = true
                    });
                }

                model.ActiveList = new List <SelectListItem>();
                if (mapItemEntity.IsActive)
                {
                    //active
                    model.ActiveList.Add(new SelectListItem()
                    {
                        Text = "Active", Value = "true", Selected = true
                    });
                    model.ActiveList.Add(new SelectListItem()
                    {
                        Text = "Inactive", Value = "false"
                    });
                }
                else
                {
                    model.ActiveList.Add(new SelectListItem()
                    {
                        Text = "Active", Value = "true"
                    });
                    model.ActiveList.Add(new SelectListItem()
                    {
                        Text = "Inactive", Value = "false", Selected = true
                    });
                }

                model.SearchFilter = new QuestionGroupEditSearchFilter()

                {
                    MapProductId = null,
                    PageNo       = 1,
                    PageSize     = 15,
                    SortField    = "",
                    SortOrder    = "ASC"
                };

                model.QuestionGroupSearchFilter = new QuestionSelectSearchFilter()
                {
                    QuestionName   = string.Empty,
                    QuestionIdList = string.Empty,
                    ProductId      = null,
                    PageNo         = 1,
                    PageSize       = 15,
                    SortField      = "",
                    SortOrder      = "ASC"
                };

                model.IsActive = mapItemEntity.IsActive;
                model.IsVerify = mapItemEntity.IsVerify;

                return(View(model));
            }

            return(View("Search"));
        }
Beispiel #7
0
        public ActionResult Edit(int?mapProductId)
        {
            if (mapProductId.HasValue)
            {
                var model = new MappingProductTypeEditModel();

                _srPageFacade = new SrPageFacade();

                var srPageList = _srPageFacade.GetSrPageList();
                model.SrPageList = srPageList.Select(item => new SelectListItem()
                {
                    Text = item.SrPageName,
                    //Value = item.SrPageId.ToString(CultureInfo.InvariantCulture)
                    Value = item.SrPageId.ToString()
                }).ToList();

                _mappingProductTypeFacade = new MappingProductTypeFacade();
                MappingProductTypeItemEntity mapItemEntity = _mappingProductTypeFacade.GetMappingById(mapProductId.Value);
                model.MapProductId        = mapItemEntity.MapProductId;
                model.ProductGroupId      = mapItemEntity.ProductGroupId;
                model.ProductGroupName    = mapItemEntity.ProductGroupName;
                model.ProductId           = mapItemEntity.ProductId;
                model.ProductName         = mapItemEntity.ProductName;
                model.CampaignServiceId   = mapItemEntity.CampaignServiceId;
                model.CampaignServiceName = mapItemEntity.CampaignName;
                model.AreaId          = mapItemEntity.AreaId;
                model.AreaName        = mapItemEntity.AreaName;
                model.SubAreaId       = mapItemEntity.SubAreaId;
                model.SubAreaName     = mapItemEntity.SubAreaName;
                model.TypeId          = mapItemEntity.TypeId;
                model.TypeName        = mapItemEntity.TypeName;
                model.OwnerBranchId   = mapItemEntity.OwnerBranchId;
                model.OwnerBranchName = mapItemEntity.OwnerBranchName;
                model.OwnerSrId       = mapItemEntity.OwnerUserId;
                model.OwnerSrName     = mapItemEntity.OwnerSrName;
                model.CreateUser      = mapItemEntity.CreateUser != null ? mapItemEntity.CreateUser.FullName : "";
                model.UpdateUser      = mapItemEntity.UpdateUser != null ? mapItemEntity.UpdateUser.FullName : "";
                model.CreateDate      = DateUtil.ToStringAsDateTime(mapItemEntity.CreateDate);
                model.UpdateDate      = DateUtil.ToStringAsDateTime(mapItemEntity.UpdateDate);
                model.SrPageId        = mapItemEntity.SrPageId;

                model.VerifyList = new List <SelectListItem>();
                if (mapItemEntity.IsVerify)
                {
                    //verify
                    model.VerifyList.Add(new SelectListItem {
                        Text = "Yes", Value = "true", Selected = true
                    });
                    model.VerifyList.Add(new SelectListItem {
                        Text = "No", Value = "false"
                    });
                }
                else
                {
                    model.VerifyList.Add(new SelectListItem {
                        Text = "Yes", Value = "true"
                    });
                    model.VerifyList.Add(new SelectListItem {
                        Text = "No", Value = "false", Selected = true
                    });
                }

                model.ActiveList = new List <SelectListItem>();
                if (mapItemEntity.IsActive)
                {
                    //active
                    model.ActiveList.Add(new SelectListItem {
                        Text = "Active", Value = "true", Selected = true
                    });
                    model.ActiveList.Add(new SelectListItem {
                        Text = "Inactive", Value = "false"
                    });
                }
                else
                {
                    model.ActiveList.Add(new SelectListItem {
                        Text = "Active", Value = "true"
                    });
                    model.ActiveList.Add(new SelectListItem {
                        Text = "Inactive", Value = "false", Selected = true
                    });
                }

                model.SearchFilter = new QuestionGroupEditSearchFilter

                {
                    MapProductId = null,
                    PageNo       = 1,
                    PageSize     = 15,
                    SortField    = "",
                    SortOrder    = "ASC"
                };

                model.QuestionGroupSearchFilter = new QuestionSelectSearchFilter
                {
                    QuestionName   = string.Empty,
                    QuestionIdList = string.Empty,
                    ProductId      = null,
                    PageNo         = 1,
                    PageSize       = 15,
                    SortField      = "",
                    SortOrder      = "ASC"
                };

                model.IsActive = mapItemEntity.IsActive;
                model.IsVerify = mapItemEntity.IsVerify;

                ViewBag.VerifyOTPList = new SelectList(new SelectListItem[]
                {
                    new SelectListItem()
                    {
                        Value = "true", Text = "Yes"
                    },
                    new SelectListItem()
                    {
                        Value = "false", Text = "No"
                    },
                },
                                                       "Value", "Text", string.Empty);

                using (MappingProductTypeFacade _mapFacade = new MappingProductTypeFacade())
                {
                    List <SelectListItem> otpTemplate = new List <SelectListItem>();
                    _mapFacade.GetOTPTemplate().ForEach(o => otpTemplate.Add(new SelectListItem()
                    {
                        Value = o.OTPTemplateId.ToString(), Text = o.OTPTemplateName
                    }));
                    ViewBag.OTPTemplateList = new SelectList(otpTemplate, "Value", "Text", string.Empty);
                }

                using (HpFacade _hpFacade = new HpFacade())
                {
                    List <SelectListItem> hpStatus = new List <SelectListItem>();
                    _hpFacade.GetHpStatus().ForEach(o => hpStatus.Add(new SelectListItem()
                    {
                        Value = o.HpStatusId.ToString(), Text = $"{o.HpLangIndeCode}-{o.HpSubject}"
                    }));
                    ViewBag.HpStatusList = new SelectList(hpStatus, "Value", "Text", string.Empty);
                }

                model.IsVerifyOTP = mapItemEntity.IsVerifyOTP;
                model.IsSRSecret  = mapItemEntity.IsSRSecret;
                model.OTPTemplate = mapItemEntity.OTPTemplate ?? model.OTPTemplate;
                model.HpStatus    = mapItemEntity.HpStatus ?? model.HpStatus;

                return(View(model));
            }

            return(View("Search"));
        }