Beispiel #1
0
        /// <summary>
        /// Validate customer group before add to table.<br />
        /// - Check is it already in table.<br />
        /// - Check is it exist Customer Group DB/<br />
        /// </summary>
        /// <param name="custGroup"></param>
        /// <returns></returns>
        public ActionResult MAS050_CheckBeforeAddCustomerGroup(MAS050_CustomerGroup custGroup)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.WARNING;

            try
            {
                if (ModelState.IsValid == false)
                {
                    ValidatorUtil.BuildErrorMessage(res, this);
                    return(Json(res));
                }

                #region Check Duplicate

                if (custGroup.CustomerGroupList != null)
                {
                    foreach (dtCustomerGroup cg in custGroup.CustomerGroupList)
                    {
                        if (cg.GroupCode == custGroup.GroupCode)
                        {
                            res.AddErrorMessage(MessageUtil.MODULE_MASTER, MessageUtil.MessageList.MSG1007);
                            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                            return(Json(res));
                        }
                    }
                }

                #endregion
                #region Check Duplicate Customer Group

                ICustomerMasterHandler hand = ServiceContainer.GetService <ICustomerMasterHandler>() as ICustomerMasterHandler;
                List <int?>            list = hand.CheckExistCustomerGroup(
                    custGroup.GroupCode,
                    custGroup.CustCode);
                if (list.Count > 0)
                {
                    if (list[0] > 0)
                    {
                        res.AddErrorMessage(MessageUtil.MODULE_MASTER, MessageUtil.MessageList.MSG1007);
                        res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                        return(Json(res));
                    }
                }

                #endregion

                IMasterHandler        handler  = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
                List <View_tbm_Group> lstGroup = handler.GetDorp_Group();
                if (lstGroup.Count > 0)
                {
                    foreach (View_tbm_Group g in lstGroup)
                    {
                        if (g.GroupCode == custGroup.GroupCode)
                        {
                            res.ResultData = g;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }