// Insert or Update public InsertOrUpdateDoNotCallCustomerResponse InsertOrUpdateDoNotCallCustomer(InsertOrUpdateDoNotCallCustomerRequest request) { string methodName = $"{nameof(DoNotCallInterfaceService)}.{nameof(InsertOrUpdateDoNotCallCustomer)}"; var response = new InsertOrUpdateDoNotCallCustomerResponse(); bool success = false; string detail = string.Empty; try { _doNotCallFacade = new DoNotCallFacade(); // Validate input data DoNotCallInterfaceValidateResult validateResult = ValidateInsertUpdateCustomerRequest(request); if (!validateResult.IsValid) { response.ResponseStatusInfo = GetInvalidInputResponse <InsertResponseStatusInfo>(validateResult.ErrorMessage); _logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject()); detail = validateResult.ErrorMessage; return(response); } response.Header = GetResponseHeader(request.Header, methodName); // Authenticate user if (!ValidateServiceRequest(request.Header)) { response.ResponseStatusInfo = GetInvalidLoginResponse <InsertResponseStatusInfo>(); detail = "Invalid login"; return(response); } _logger.DebugFormat("-- XMLRequest --\n{0}", request.SerializeObject()); // Map model to insert DoNotCallByCustomerEntity entity = MapCustomerEntity(request, validateResult); // Insert data int transactionId = _doNotCallFacade.SaveCustomerFromInterface(entity); if (transactionId > 0) { response.ResponseStatusInfo = GetSuccessResponseStatusInfo <InsertResponseStatusInfo>(); response.ResponseStatusInfo.TransactionId = transactionId; success = true; } return(response); } catch (Exception ex) { response.ResponseStatusInfo = GetErrorResponse <InsertResponseStatusInfo>(ex); detail = ex.Message; return(response); } finally { InsertAuditLog(methodName, success, detail ?? response.ResponseStatusInfo.ResponseMessage); } }
private DoNotCallByCustomerEntity MapCustomerEntity <T>(T request, DoNotCallInterfaceValidateResult validateResult) where T : DoNotCallTransactionInput { DateTime now = DateTime.Now; _commonFacade = new CommonFacade(); string neverExpireDate = _commonFacade.GetCacheParamByName("DNC_NEVER_EXPIRE_DATE").ParamValue; DateTime nonExpireDate = DateTimeHelpers.ParseDateTime(neverExpireDate, "yyyy-MM-dd").Value; bool isActive = request.Status == Constants.DigitTrue; DateTime expireDate = isActive ? request.ExpiryDate.HasValue ? request.ExpiryDate.Value : now.Date.AddYears(1).Date : now.Date; // if inactive set expire date to today bool isBlockAllSalesProducts = validateResult.IsBlockAllSalesProducts; bool isBlockAllInfoProducts = validateResult.IsBlockAllInfoProducts; List <DoNotCallActivityProductInput> blockSalesProducts = isBlockAllSalesProducts ? new List <DoNotCallActivityProductInput>() : validateResult.ActivityProducts .Where(x => x.BlockType == Constants.ActivityProductTypeSales) .ToList(); List <DoNotCallActivityProductInput> blockInfoProducts = isBlockAllInfoProducts ? new List <DoNotCallActivityProductInput>() : validateResult.ActivityProducts .Where(x => x.BlockType == Constants.ActivityProductTypeInformation) .ToList(); // check user exists? _userFacade = new UserFacade(); UserEntity user = _userFacade.GetUserByLogin(request.UpdateUser) ?? new UserEntity { UserId = 0, Username = request.UpdateUser }; var entity = new DoNotCallByCustomerEntity { CurrentUserId = user.UserId, CurrentUsername = user.Username, CurrentUserIpAddress = ApplicationHelpers.GetClientIP(), BasicInfo = new DoNotCallBasicInfoModel { FirstName = request.FirstName, LastName = request.LastName, TransactionId = validateResult.TransactionId ?? 0, EffectiveDate = now.Date, CreateDate = now, UpdateDate = now, IsNeverExpire = expireDate.Date == nonExpireDate.Date, ExpireDate = expireDate, FromSystem = request.SystemCode, IsActive = isActive, Remark = request.Remark }, CardInfo = new DoNotCallCardInfoModel { CardNo = request.CardNo, SubscriptionTypeId = validateResult.SubscriptionTypeId.Value }, ContactDetail = new DoNotCallContactModel { Email = new DoNotCallEmail { EmailList = request.EmailList?.Select(email => new DoNotCallEmailModel { Email = email.Email, Id = email.Id.HasValue? email.Id.Value: 0, IsDeleted = email.IsActive == Constants.FlagN, LastUpdateDate = now }).ToList() ?? new List <DoNotCallEmailModel>() }, Telephone = new DoNotCallTelephone { TelephoneList = request.TelephoneList?.Select(phoneNo => new DoNotCallTelephoneModel { PhoneNo = phoneNo.PhoneNo, Id = phoneNo.Id.HasValue? phoneNo.Id.Value: 0, IsDeleted = phoneNo.IsActive == Constants.FlagN, LastUpdateDate = now }).ToList() ?? new List <DoNotCallTelephoneModel>() } }, BlockSales = new DoNotCallBlockSalesModel { IsBlockAllSalesProducts = isBlockAllSalesProducts, IsBlockSalesEmail = request.SalesBlockInfo.BlockEmail == Constants.DigitTrue, IsBlockSalesSms = request.SalesBlockInfo.BlockSMS == Constants.DigitTrue, IsBlockSalesTelephone = request.SalesBlockInfo.BlockTelephone == Constants.DigitTrue, BlockSalesProductList = blockSalesProducts.Select(product => new DoNotCallProductModel { ActivityProductType = Constants.ActivityProductTypeSales, CreateDate = now, IsDeleted = product.IsActive == Constants.FlagN, Id = product.ProductId.Value, ActivityProductId = product.ActivityProductId, ProductId = product.ProductId.HasValue ? product.ProductId.Value: 0, UpdateDate = now }).ToList() ?? new List <DoNotCallProductModel>() }, BlockInformation = new DoNotCallBlockInformationModel { IsBlockAllInfoProducts = isBlockAllInfoProducts, IsBlockInfoEmail = request.InformationBlockInfo.BlockEmail == Constants.DigitTrue, IsBlockInfoSms = request.InformationBlockInfo.BlockSMS == Constants.DigitTrue, IsBlockInfoTelephone = request.InformationBlockInfo.BlockTelephone == Constants.DigitTrue, BlockInfoProductList = blockInfoProducts.Select(product => new DoNotCallProductModel { ActivityProductType = Constants.ActivityProductTypeInformation, CreateDate = now, IsDeleted = product.IsActive == Constants.FlagN, Id = product.ProductId.Value, ActivityProductId = product.ActivityProductId, ProductId = product.ProductId.HasValue ? product.ProductId.Value: 0, UpdateDate = now }).ToList() ?? new List <DoNotCallProductModel>() } }; return(entity); }