コード例 #1
0
        private List <TransactionInfo> SearchDoNotCallTransaction(InquireDoNotCallRequest request)
        {
            _doNotCallFacade = new DoNotCallFacade();
            var cardNo = request.CardNo;

            var searchFilter = new DoNotCallListSearchFilter
            {
                CardNo      = cardNo,
                Telephone   = request.PhoneNo,
                Email       = request.Email,
                PageNo      = 1,
                PageSize    = request.DataLimit,
                ProductCode = request.ProductCode
            };

            if (!string.IsNullOrWhiteSpace(cardNo))
            {
                string code = request.SubscriptionTypeCode;
                int?   subscriptionTypeId = _commonFacade.GetSubscriptTypeByCode(code)?.SubscriptTypeId;
                if (!subscriptionTypeId.HasValue)
                {
                    throw new NullReferenceException($"Subscription Type Code: {code} not found.");
                }
                else
                {
                    searchFilter.SubscriptionTypeId = subscriptionTypeId.Value;
                }
            }

            List <TransactionInfo> result = _doNotCallFacade.SearchExactDoNotCallTransaction(searchFilter);

            return(result);
        }
コード例 #2
0
        private DoNotCallInterfaceValidateResult ValidateInsertUpdateCustomerRequest(InsertOrUpdateDoNotCallCustomerRequest request)
        {
            var  result = new DoNotCallInterfaceValidateResult();
            bool valid  = ValidateRequestModel(request, result);

            if (valid) // validate with database
            {
                // check item alreayd exist (get id and update date)
                DoNotCallTransactionInfo info = _doNotCallFacade.GetCustomerTransaction(request.CardNo, request.SubscriptTypeCode);
                bool isExistingTransaction    = info != null && info.TransactionId > 0;
                if (isExistingTransaction && info.UpdateDate > request.UpdateDate)
                {
                    result.ErrorMessage = $"Transaction already exists (transaction ID: {info.TransactionId})";
                }
                else if (isExistingTransaction && info.IsBlockAllInfoProduct && request.InformationBlockInfo.BlockProducts.Count > 0)
                {
                    result.ErrorMessage = $"Cannot add block product to Information block product list. The current setting is block ALL products.";
                }
                else if (isExistingTransaction && info.IsBlockAllSalesProduct && request.SalesBlockInfo.BlockProducts.Count > 0)
                {
                    result.ErrorMessage = $"Cannot add block product to Sales block product list. The current setting is block ALL products.";
                }
                else
                {
                    if (isExistingTransaction) // For Update
                    {
                        result.IsBlockAllInfoProducts  = info.IsBlockAllInfoProduct;
                        result.IsBlockAllSalesProducts = info.IsBlockAllSalesProduct;
                        // remove duplicated email
                        if (request.EmailList != null && request.EmailList.Count > 0 && info.Emails.Count > 0)
                        {
                            var removeItemList = new List <BlockEmail>();
                            foreach (var inputItem in request.EmailList)
                            {
                                var  existingItems     = info.Emails.Where(x => x.Email.Equals(inputItem.Email, StringComparison.InvariantCultureIgnoreCase)).ToList();
                                bool itemAlreadyExists = existingItems != null && existingItems.Count > 0;

                                if (itemAlreadyExists)
                                {
                                    bool inputItemIsActive       = inputItem.IsActive == Constants.FlagY;
                                    var  activeItem              = existingItems.FirstOrDefault(x => !x.IsDeleted);
                                    bool haveExistingActiveItem  = activeItem != null;
                                    bool haveExistingDeletedItem = existingItems.Any(x => x.IsDeleted);

                                    bool itemAlreadyActive  = haveExistingActiveItem && inputItemIsActive;
                                    bool itemAlreadyDeleted = !haveExistingActiveItem && haveExistingDeletedItem && !inputItemIsActive;
                                    if (itemAlreadyActive || itemAlreadyDeleted)
                                    {
                                        removeItemList.Add(inputItem);
                                    }
                                    else if (haveExistingActiveItem && !inputItemIsActive) // have item to delete
                                    {
                                        inputItem.Id = activeItem.Id;
                                    }
                                }
                            }

                            // remove items
                            request.EmailList = request.EmailList.Except(removeItemList).ToList();
                        }
                        // remove duplicated phone no
                        if (request.TelephoneList != null && request.TelephoneList.Count > 0 && info.Telephones.Count > 0)
                        {
                            var removeItemList = new List <BlockPhoneNo>();
                            foreach (var inputItem in request.TelephoneList)
                            {
                                var  existingItems     = info.Telephones.Where(x => x.PhoneNo.Equals(inputItem.PhoneNo, StringComparison.InvariantCultureIgnoreCase)).ToList();
                                bool itemAlreadyExists = existingItems != null && existingItems.Count > 0;

                                if (itemAlreadyExists)
                                {
                                    bool inputItemIsActive       = inputItem.IsActive == Constants.FlagY;
                                    var  activeItem              = existingItems.FirstOrDefault(x => !x.IsDeleted);
                                    bool haveExistingActiveItem  = activeItem != null;
                                    bool haveExistingDeletedItem = existingItems.Any(x => x.IsDeleted);

                                    bool itemAlreadyActive  = haveExistingActiveItem && inputItemIsActive;
                                    bool itemAlreadyDeleted = !haveExistingActiveItem && haveExistingDeletedItem && !inputItemIsActive;
                                    if (itemAlreadyActive || itemAlreadyDeleted)
                                    {
                                        removeItemList.Add(inputItem);
                                    }
                                    else if (haveExistingActiveItem && !inputItemIsActive) // have item to delete
                                    {
                                        inputItem.Id = activeItem.Id;
                                    }
                                }
                            }

                            // remove items
                            request.TelephoneList = request.TelephoneList.Except(removeItemList).ToList();
                        }
                    }

                    result.TransactionId = info?.TransactionId;
                    // check subscription type code exisst
                    _commonFacade = new CommonFacade();
                    string subscriptTypeCode = request.SubscriptTypeCode;
                    int?   subTypeId         = _commonFacade.GetSubscriptTypeByCode(subscriptTypeCode)?.SubscriptTypeId;
                    if (!subTypeId.HasValue)
                    {
                        result.ErrorMessage = $"Subscript type code {subscriptTypeCode} not found";
                    }
                    else
                    {
                        // check product exists
                        result.SubscriptionTypeId = subTypeId.Value;
                        ValidateProductCodes(request, result);
                        if (result.IsValid && isExistingTransaction)
                        {
                            // Sales
                            var removeSalesProductList = new List <DoNotCallActivityProductInput>();
                            foreach (var inputItem in result.ActivityProducts)
                            {
                                var  existingItems     = info.SalesProducts.Where(x => x.ProductId == inputItem.ProductId).ToList();
                                bool itemAlreadyExists = existingItems != null && existingItems.Count > 0;

                                if (itemAlreadyExists)
                                {
                                    bool inputItemIsActive       = inputItem.IsActive == Constants.FlagY;
                                    var  activeItem              = existingItems.FirstOrDefault(x => !x.IsDeleted);
                                    bool haveExistingActiveItem  = activeItem != null;
                                    bool haveExistingDeletedItem = existingItems.Any(x => x.IsDeleted);

                                    bool itemAlreadyActive  = haveExistingActiveItem && inputItemIsActive;
                                    bool itemAlreadyDeleted = !haveExistingActiveItem && haveExistingDeletedItem && !inputItemIsActive;
                                    if (itemAlreadyActive || itemAlreadyDeleted)
                                    {
                                        removeSalesProductList.Add(inputItem);
                                    }
                                    else if (haveExistingActiveItem && !inputItemIsActive) // have item to delete
                                    {
                                        inputItem.ProductId = activeItem.ProductId;
                                    }
                                }
                            }
                            // Info
                            var removeInfoProductList = new List <DoNotCallActivityProductInput>();
                            foreach (var inputItem in result.ActivityProducts)
                            {
                                var  existingItems     = info.InfoProducts.Where(x => x.ProductId == inputItem.ProductId).ToList();
                                bool itemAlreadyExists = existingItems != null && existingItems.Count > 0;

                                if (itemAlreadyExists)
                                {
                                    bool inputItemIsActive       = inputItem.IsActive == Constants.FlagY;
                                    var  activeItem              = existingItems.FirstOrDefault(x => !x.IsDeleted);
                                    bool haveExistingActiveItem  = activeItem != null;
                                    bool haveExistingDeletedItem = existingItems.Any(x => x.IsDeleted);

                                    bool itemAlreadyActive  = haveExistingActiveItem && inputItemIsActive;
                                    bool itemAlreadyDeleted = !haveExistingActiveItem && haveExistingDeletedItem && !inputItemIsActive;
                                    if (itemAlreadyActive || itemAlreadyDeleted)
                                    {
                                        removeInfoProductList.Add(inputItem);
                                    }
                                    else if (haveExistingActiveItem && !inputItemIsActive) // have item to delete
                                    {
                                        inputItem.ProductId = activeItem.ProductId;
                                    }
                                }
                            }
                            // remove items
                            result.ActivityProducts = result.ActivityProducts.Except(removeInfoProductList).ToList();
                        }
                    }
                }
            }

            result.IsValid = string.IsNullOrWhiteSpace(result.ErrorMessage);

            return(result);
        }
コード例 #3
0
        private DoNotCallInterfaceValidateResult ValidateInsertUpdatePhoneRequest(InsertOrUpdateDoNotCallPhoneRequest request)
        {
            var  result = new DoNotCallInterfaceValidateResult();
            bool valid  = ValidateRequestModel(request, result);

            if (valid) // validate with database
            {
                // check item alreayd exist (get id and update date)
                if (request.TransactionId != 0)
                {
                    int transactionId             = request.TransactionId;
                    DoNotCallTransactionInfo info = _doNotCallFacade.GetTelephoneTransactionById(transactionId);
                    if (info == null)
                    {
                        result.ErrorMessage = $"Transaction ID: {transactionId} not found.";
                    }
                    else if (info.UpdateDate > request.UpdateDate)
                    {
                        result.ErrorMessage = $"Transaction already updated (Transaction ID: {info.TransactionId})";
                    }
                    else if (info.IsBlockAllInfoProduct && request.InformationBlockInfo.BlockProducts.Count > 0)
                    {
                        result.ErrorMessage = $"Cannot add block product to Information block product list. The current setting is block ALL products.";
                    }
                    else if (info.IsBlockAllSalesProduct && request.SalesBlockInfo.BlockProducts.Count > 0)
                    {
                        result.ErrorMessage = $"Cannot add block product to Sales block product list. The current setting is block ALL products.";
                    }
                    else
                    {
                        result.IsBlockAllInfoProducts  = info.IsBlockAllInfoProduct;
                        result.IsBlockAllSalesProducts = info.IsBlockAllSalesProduct;
                        // remove duplicated email
                        if (request.EmailList != null && request.EmailList.Count > 0 && info.Emails.Count > 0)
                        {
                            request.EmailList.RemoveAll(email => info.Emails
                                                        .Any(y => y.Email.Equals(email.Email, StringComparison.InvariantCultureIgnoreCase) &&
                                                             y.IsDeleted == email.IsDeleted));
                        }
                        // remove duplicated phone no
                        if (request.TelephoneList != null && request.TelephoneList.Count > 0 && info.Telephones.Count > 0)
                        {
                            request.TelephoneList.RemoveAll(phoneNo => info.Telephones
                                                            .Any(y => y.PhoneNo.Equals(phoneNo.PhoneNo, StringComparison.InvariantCultureIgnoreCase) &&
                                                                 y.IsDeleted == phoneNo.IsDeleted));
                        }

                        result.TransactionId = info.TransactionId;
                        // check subscription type code exisst
                        if (!string.IsNullOrWhiteSpace(request.SubscriptTypeCode))
                        {
                            _commonFacade = new CommonFacade();
                            string subscriptTypeCode = request.SubscriptTypeCode;
                            int?   subTypeId         = _commonFacade.GetSubscriptTypeByCode(subscriptTypeCode)?.SubscriptTypeId;
                            if (!subTypeId.HasValue)
                            {
                                result.ErrorMessage = $"Subscript type code {subscriptTypeCode} not found";
                            }
                            else
                            {
                                // check product exists
                                result.SubscriptionTypeId = subTypeId.Value;
                            }
                        }

                        ValidateProductCodes(request, result);

                        if (result.IsValid)
                        {
                            // check duplicated sales product
                            result.ActivityProducts.RemoveAll(x => x.BlockType == Constants.ActivityProductTypeSales &&
                                                              info.SalesProducts.Any(y => y.ProductId == x.ProductId && x.IsDeleted == y.IsDeleted));
                            // check duplicated info product
                            result.ActivityProducts.RemoveAll(x => x.BlockType == Constants.ActivityProductTypeInformation &&
                                                              info.InfoProducts.Any(y => y.ProductId == x.ProductId && x.IsDeleted == y.IsDeleted));
                        }
                    }
                }
                else
                {
                    // check subscription type code exisst
                    if (!string.IsNullOrWhiteSpace(request.SubscriptTypeCode))
                    {
                        _commonFacade = new CommonFacade();
                        string subscriptTypeCode = request.SubscriptTypeCode;
                        int?   subTypeId         = _commonFacade.GetSubscriptTypeByCode(subscriptTypeCode)?.SubscriptTypeId;
                        if (!subTypeId.HasValue)
                        {
                            result.ErrorMessage = $"Subscript type code {subscriptTypeCode} not found";
                        }
                        else
                        {
                            // check product exists
                            result.SubscriptionTypeId = subTypeId.Value;
                        }
                    }

                    ValidateProductCodes(request, result);
                }
            }
            result.IsValid = string.IsNullOrWhiteSpace(result.ErrorMessage);

            return(result);
        }
コード例 #4
0
ファイル: ContactController.cs プロジェクト: KKPBank/CSM
        public ActionResult ManageContactRlat(ContactEditViewModel contactEditVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit Contact").Add("FirstNameThai", contactEditVM.FirstNameThai).ToInputLogString());

            try
            {
                #region "Validate CardNo"

                if (!string.IsNullOrEmpty(contactEditVM.SubscriptType))
                {
                    _commonFacade = new CommonFacade();
                    var subscriptTypePersonal =
                        _commonFacade.GetSubscriptTypeByCode(Constants.SubscriptTypeCode.Personal);
                    if (string.IsNullOrEmpty(contactEditVM.CardNo))
                    {
                        ModelState.AddModelError("CardNo", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_RequiredField, Resource.Lbl_CardNo_Passport));
                    }
                    else if (contactEditVM.SubscriptType.ToNullable <int>() == subscriptTypePersonal.SubscriptTypeId)
                    {
                        if (!ApplicationHelpers.ValidateCardNo(contactEditVM.CardNo))
                        {
                            ModelState.AddModelError("CardNo", Resource.ValErr_InvalidCardNo);
                        }
                    }
                }

                #endregion

                #region "Validate FirstName"

                if (string.IsNullOrEmpty(contactEditVM.FirstNameThai) &&
                    string.IsNullOrEmpty(contactEditVM.FirstNameEnglish))
                {
                    ModelState.AddModelError("FirstNameThai", string.Format(CultureInfo.InvariantCulture, Resource.ValErr_RequiredField, Resource.Lbl_FirstNameThai_Contact));
                }


                #endregion

                #region  "Validate Phone"

                if (contactEditVM.IsEdit == "1")
                {
                    if (string.IsNullOrEmpty(contactEditVM.PhoneType2))
                    {
                        ModelState.Remove("PhoneNo2");
                    }
                    if (string.IsNullOrEmpty(contactEditVM.PhoneType3))
                    {
                        ModelState.Remove("PhoneNo3");
                    }

                    // Check duplicate phoneNo
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo1) && !string.IsNullOrEmpty(contactEditVM.PhoneNo2))
                    {
                        if (contactEditVM.PhoneNo1.Equals(contactEditVM.PhoneNo2))
                        {
                            ModelState.AddModelError("PhoneNo1", Resource.ValError_DuplicatePhoneNo);
                            ModelState.AddModelError("PhoneNo2", Resource.ValError_DuplicatePhoneNo);
                        }
                    }

                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo1) && !string.IsNullOrEmpty(contactEditVM.PhoneNo3))
                    {
                        if (contactEditVM.PhoneNo1.Equals(contactEditVM.PhoneNo3))
                        {
                            ModelState.AddModelError("PhoneNo1", Resource.ValError_DuplicatePhoneNo);
                            ModelState.AddModelError("PhoneNo3", Resource.ValError_DuplicatePhoneNo);
                        }
                    }

                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo2) && !string.IsNullOrEmpty(contactEditVM.PhoneNo3))
                    {
                        if (contactEditVM.PhoneNo2.Equals(contactEditVM.PhoneNo3))
                        {
                            ModelState.AddModelError("PhoneNo2", Resource.ValError_DuplicatePhoneNo);
                            ModelState.AddModelError("PhoneNo3", Resource.ValError_DuplicatePhoneNo);
                        }
                    }
                }
                else
                {
                    // Phone
                    ModelState.Remove("PhoneType1");
                    ModelState.Remove("PhoneNo1");
                    ModelState.Remove("PhoneNo2");
                    ModelState.Remove("PhoneNo3");

                    // Name
                    ModelState.Remove("FirstNameThai");
                    ModelState.Remove("FirstNameEnglish");
                    ModelState.Remove("LastNameThai");
                    ModelState.Remove("LastNameEnglish");
                }

                #endregion

                if (!string.IsNullOrEmpty(contactEditVM.BirthDate) && !contactEditVM.BirthDateValue.HasValue)
                {
                    ModelState.AddModelError("BirthDate", Resource.ValErr_InvalidDate);
                }
                else if (!string.IsNullOrEmpty(contactEditVM.BirthDate) && contactEditVM.BirthDateValue.HasValue)
                {
                    if (contactEditVM.BirthDateValue.Value > DateTime.Now.Date)
                    {
                        ModelState.AddModelError("BirthDate", Resource.ValErr_InvalidDate_MustLessThanToday);
                    }
                }

                if (ModelState.IsValid)
                {
                    _customerFacade = new CustomerFacade();

                    #region "Check Duplicate PhoneNo"

                    List <string> lstPhoneNo = new List <string>();
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo1))
                    {
                        lstPhoneNo.Add(contactEditVM.PhoneNo1);
                    }
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo2))
                    {
                        lstPhoneNo.Add(contactEditVM.PhoneNo2);
                    }
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo3))
                    {
                        lstPhoneNo.Add(contactEditVM.PhoneNo3);
                    }

                    if (contactEditVM.IsEdit != "0")
                    {
                        contactEditVM.ContactList = _customerFacade.GetContactByPhoneNo(contactEditVM.ContactId,
                                                                                        contactEditVM.FirstNameThai, contactEditVM.LastNameThai
                                                                                        , contactEditVM.FirstNameEnglish, contactEditVM.LastNameEnglish, lstPhoneNo);
                    }

                    if (contactEditVM.ContactList != null && contactEditVM.ContactList.Any())
                    {
                        if (contactEditVM.IsConfirm == "0") // Case New
                        {
                            // Show DuplicateList
                            return(PartialView("~/Views/Contact/_ContactDuplicateList.cshtml", contactEditVM));
                        }
                        else // Case Edit
                        {
                            // Alert Duplicate
                            return(Json(new
                            {
                                Valid = false,
                                Error = Resource.ValError_DuplicateContact,
                                Errors = string.Empty
                            }));
                        }
                    }

                    #endregion

                    ContactEntity contactEntity = new ContactEntity
                    {
                        ContactId     = contactEditVM.ContactId,
                        SubscriptType = new SubscriptTypeEntity
                        {
                            SubscriptTypeId = contactEditVM.SubscriptType.ToNullable <int>()
                        },
                        CardNo    = contactEditVM.CardNo,
                        BirthDate = contactEditVM.BirthDateValue,
                        TitleThai = new TitleEntity
                        {
                            TitleId = contactEditVM.TitleThai.ToNullable <int>()
                        },
                        FirstNameThai = contactEditVM.FirstNameThai,
                        LastNameThai  = contactEditVM.LastNameThai,
                        TitleEnglish  = new TitleEntity
                        {
                            TitleId = contactEditVM.TitleEnglish.ToNullable <int>()
                        },
                        FirstNameEnglish = contactEditVM.FirstNameEnglish,
                        LastNameEnglish  = contactEditVM.LastNameEnglish,
                        Email            = contactEditVM.Email,
                        CreateUser       = new UserEntity
                        {
                            UserId = this.UserInfo.UserId
                        },
                        UpdateUser = new UserEntity
                        {
                            UserId = this.UserInfo.UserId
                        },
                        CustomerId = contactEditVM.CustomerId // for add CustomerLog
                    };

                    #region "Phone & Fax"

                    // Phone & Fax
                    contactEntity.PhoneList = new List <PhoneEntity>();
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo1))
                    {
                        contactEntity.PhoneList.Add(new PhoneEntity {
                            PhoneTypeId = contactEditVM.PhoneType1.ToNullable <int>(), PhoneNo = contactEditVM.PhoneNo1
                        });
                    }
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo2))
                    {
                        contactEntity.PhoneList.Add(new PhoneEntity {
                            PhoneTypeId = contactEditVM.PhoneType2.ToNullable <int>(), PhoneNo = contactEditVM.PhoneNo2
                        });
                    }
                    if (!string.IsNullOrEmpty(contactEditVM.PhoneNo3))
                    {
                        contactEntity.PhoneList.Add(new PhoneEntity {
                            PhoneTypeId = contactEditVM.PhoneType3.ToNullable <int>(), PhoneNo = contactEditVM.PhoneNo3
                        });
                    }
                    // Fax
                    if (!string.IsNullOrEmpty(contactEditVM.Fax))
                    {
                        _commonFacade = new CommonFacade();
                        var phoneTypeFax = _commonFacade.GetPhoneTypeByCode(Constants.PhoneTypeCode.Fax);
                        contactEntity.PhoneList.Add(new PhoneEntity {
                            PhoneTypeId = phoneTypeFax.PhoneTypeId, PhoneNo = contactEditVM.Fax
                        });
                    }
                    #endregion

                    // Save
                    var contactRelationship = contactEditVM.ContactRelationshipList.Where(x => x.IsEdit == true).ToList();

                    bool isSuccess = false;
                    if (contactEditVM.IsConfirm == "0")
                    {
                        isSuccess = _customerFacade.SaveContact(contactEntity, null); // save contact only
                    }
                    else
                    {
                        #region "Validate ContactRelationship"

                        if (contactEditVM.ContactRelationshipList.Count(x => x.CustomerId == contactEditVM.CustomerId) == 0)
                        {
                            // Alert
                            return(Json(new
                            {
                                Valid = false,
                                Error = Resource.Msg_PleaseInputRelationship,
                                Errors = string.Empty
                            }));
                        }


                        #endregion

                        isSuccess = _customerFacade.SaveContact(contactEntity, contactRelationship); // save contact & relationship
                    }

                    if (isSuccess)
                    {
                        return(Json(new
                        {
                            Valid = true,
                            contactId = contactEntity.ContactId,
                        }));
                    }
                    else
                    {
                        return(Json(new
                        {
                            Valid = false,
                            Error = Resource.Error_System,
                            Errors = string.Empty
                        }));
                    }
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Edit Contact").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = Resource.Error_System,
                    Errors = string.Empty
                }));
            }
        }