public tk_FreeEventCustomers SaveFreeEventCustomer(GenericViewModel model, int ticketID)
        {
            var    cust    = new tk_FreeEventCustomers();
            string tranRef = string.Empty;

            try
            {
                if (model != null)
                {
                    cust.DateCreated = DateTime.Now;
                    cust.Email       = model.FreeEventCustomerEmail;
                    cust.EventId     = ticketID;
                    cust.Fullname    = model.FreeEventCustomerName;
                    cust.PhoneNo     = model.FreeEventCustomerPhoneNo;
                    cust.NoOfPersons = model.FreeEventNoofPersons;
                    cust.IsEmailSent = "N";
                    cust.UserId      = 1;
                    cust.Status      = "SUCCESSFULL";
                    cust.Retry       = 0;
                    cust.ReferenceNo = RefferenceGenerator.GenerateReference(GetCurrentCounter());
                    repoFreeEventCustomers.Add(cust);
                    var retV1 = unitOfWork.CommitNonAsync(1) > 0 ? true : false;
                    if (retV1)
                    {
                        var counter = repotk_BatchCounter.GetNonAsync(null);
                        counter.BatchNo = counter.BatchNo + 1;
                        repotk_BatchCounter.Update(counter);
                        var rtv = unitOfWork.CommitNonAsync(1) > 0 ? true : false;

                        // Save SMS Table
                        // Insert Into PromoLog Table
                        var sms = new tk_Sms();
                        sms.DateCreated = DateTime.Now;
                        sms.Retry       = 0;
                        sms.Message     = "Dear " + cust.Fullname + ", Your Ticket Planet Ref is: " + cust.ReferenceNo + " this RefNo  is required for Confirmation at the Event";
                        sms.PhoneNo     = cust.PhoneNo;
                        sms.IsSent      = "N";
                        repoSms.Add(sms);
                        var retV3 = unitOfWork.CommitNonAsync(1) > 0 ? true : false;

                        return(cust);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(cust);
        }
        /// <summary>
        /// 申请验证码
        /// </summary>
        /// <param name="phone"></param>
        /// <returns>开发阶段返回 { phone = xxxx, sentCode = xxxx }</returns>
        public IHttpActionResult Post([FromBody] string phone)
        {
            //1. Generate Verifycode and saved to DB
            //2. Sendout verifycode via SMS provider
            var code    = GenerateRandomNumber(6);
            var message = "【有序科技】您的注册验证码为:" + code + "。请在5分钟内输入";
            var sms     = new SMSSendRequest()
            {
                CreatedOn = DateTime.Now, Message = message, VerifyCode = code, Phone = phone, ValidUntil = DateTime.Now.AddMinutes(5), LastUpdatedOn = DateTime.Now, Status = SMSSendRequest.RequestStatus.Created
            };

            smsRepository.Add(sms);
            unitOfWork.Commit();
            var serviceResult = SmsServiceProvider.SendSms(phone, message);

            if (!serviceResult)
            {
                sms.LastUpdatedOn = DateTime.Now;
                sms.Status        = SMSSendRequest.RequestStatus.Send;
                smsRepository.Update(sms);
                unitOfWork.Commit();
                return(InternalServerError(new Exception("短信发送服务失败")));
            }
            else
            {
                sms.LastUpdatedOn = DateTime.Now;
                sms.Status        = SMSSendRequest.RequestStatus.Send;
                smsRepository.Update(sms);
                unitOfWork.Commit();
#if DEBUG
                return(Ok(new { phone = phone, sentCode = code }));
#endif
                return(Ok());
            }
        }
Exemple #3
0
        void SaveSms(Sms sms)
        {
            //recover validator
            var validator = EntityValidatorFactory.CreateValidator();

            if (validator.IsValid(sms)) //if favorite is valid
            {
                //add the favorite into the repository
                _smsRepository.Add(sms);

                //commit the unit of work
                _smsRepository.UnitOfWork.Commit();
            }
            else //customer is not valid, throw validation errors
            {
                throw new ApplicationValidationErrorsException(validator.GetInvalidMessages <Sms>(sms));
            }
        }
Exemple #4
0
        public GeneralResponse AddSms(AddSmsRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Sms sms = new Sms();
                sms.ID             = Guid.NewGuid();
                sms.CreateDate     = PersianDateTime.Now;
                sms.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                sms.Body           = request.Body;
                sms.Customer       = this._customerRepository.FindBy(request.CustomerID);
                sms.Note           = request.Note;
                sms.RowVersion     = 1;

                #region Validation

                if (sms.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in sms.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                #endregion

                _smsRepository.Add(sms);
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }
        /// <summary>
        /// Добавить вызов в очередь и сообщить об этом оператору.
        /// </summary>
        public async Task AddIncomingCall(IncomingInboxIntegrationEvent incomingInboxIntegrationEvent)
        {
            var itemId = incomingInboxIntegrationEvent.ItemId;

            if (itemId == default)
            {
                _logger.Warning($"Empty {nameof(itemId)}: {itemId}");
                return;
            }

            var extension = incomingInboxIntegrationEvent.CallerExtension;

            if (string.IsNullOrWhiteSpace(extension))
            {
                _logger.Warning($"AddIncomingCall. Empty CallerExtension. {nameof(itemId)}: {itemId}");
                return;
            }

            using UnitOfWork unitOfWork = _unitOfWork.Begin();

            bool isSms = incomingInboxIntegrationEvent.ContractInboxItemType == ContractInboxItemType.Sms;

            var smsMessageData = _mapper.Map <SmsMessageData>(incomingInboxIntegrationEvent.Sms);
            var caller         = await GetCaller(extension);

            if (isSms)
            {
                var locationMetadata = JsonConvert.SerializeObject(smsMessageData.Location ?? new SmsLocationData {
                    Position = new SmsPositionData()
                });
                var sms = new Sms(itemId)
                {
                    Status           = SmsStatus.New,
                    ArrivalDateTime  = incomingInboxIntegrationEvent.ArrivalDateTime,
                    Text             = smsMessageData.Message,
                    Applicant        = caller,
                    LocationMetadata = locationMetadata,
                    Timestamp        = smsMessageData.Timestamp
                };

                await _smsRepository.Add(sms);

                await unitOfWork.CommitAsync();

                _logger.Debug($"Added incoming sms with id: {itemId}");
            }
            else
            {
                var result = await _callManagementServiceClient.AddIncomingCall(
                    itemId,
                    caller.Id,
                    incomingInboxIntegrationEvent.ArrivalDateTime);

                if (result.IsFailure)
                {
                    _logger.Error($"AddIncomingCall. {result.ErrorMessage}");
                    return;
                }

                await _participantRepository.Add(caller);

                await unitOfWork.CommitAsync();
            }

            await _phoneHubMessageService.NotifyUsersAboutInboxUpdate(incomingInboxIntegrationEvent.InboxId);
        }
Exemple #6
0
 /// <summary>
 /// Add an sms
 /// </summary>
 /// <param name="sms"></param>
 /// <returns></returns>
 public int AddSms(SmsDomain sms)
 {
     ValidateSmsModel(sms);
     return(_smsRepository.Add(sms));
 }
        public GeneralResponse PrepareToAddCustomerLevel(AddCustomerLevelRequest request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                CustomerLevel customerLevel = new CustomerLevel();
                customerLevel.ID             = Guid.NewGuid();
                customerLevel.CreateDate     = PersianDateTime.Now;
                customerLevel.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID);
                customerLevel.Customer       = this._customerRepository.FindBy(request.CustomerID);
                customerLevel.Level          = this._levelRepository.FindBy(request.NewLevelID);
                customerLevel.Note           = request.Note;


                customerLevel.RowVersion = 1;

                #region Validation

                if (customerLevel.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in customerLevel.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                #endregion

                #region Check Conditions

                if (customerLevel.Customer.Center == null)
                {
                    response.ErrorMessages.Add("هیچ گونه مرکز مخابراتی برای مشتری مورد نظر تعریف نشده است. لطفاً با مراجعه به تنظیمات، مرکز مخابراتی مربوط به پیش شماره مشتری را تعریف کنید.");

                    return(response);
                }

                CheckConditionResponse cres = CheckLevelCondition(customerLevel.Level, customerLevel.Customer);
                if (!cres.CanEnter)
                {
                    foreach (string error in cres.ErrorMessages)
                    {
                        response.ErrorMessages.Add(error);
                    }

                    return(response);
                }

                #endregion

                #region Change Customer Query Count

                #endregion

                #region CreateSupport

                if (customerLevel.Level.CreateSupportOnEnter)
                {
                    Support support = new Support();
                    support.ID             = Guid.NewGuid();
                    support.CreateDate     = PersianDateTime.Now;
                    support.CreateEmployee = customerLevel.CreateEmployee;
                    support.SupportTitle   = "پشتیبانی ";
                    support.SupportComment = "پشتیبانی ایجاد شده خودکار توسط سیستم";
                    support.Customer       = customerLevel.Customer;
                    support.CreateBy       = Support.Creator.BySystem;
                    support.SupportStatus  =
                        _supportStatusRepository.FindAll().Where(x => x.Key == "NoStatus").FirstOrDefault();
                    _supportRepository.Add(support);
                }

                #endregion

                _customerLevelRepository.Add(customerLevel);

                #region Query Customer Count

                //اگر مشتری جدید بود فقط به مرحله جدید یک واحد اضافه کن
                if (request.NewCustomer == true)
                {
                    Infrastructure.Querying.Query newQuery = new Infrastructure.Querying.Query();
                    Criterion crt1 = new Criterion("Level.ID", request.NewLevelID, CriteriaOperator.Equal);
                    newQuery.Add(crt1);
                    Model.Customers.Query OldQuery = _queryRepository.FindBy(newQuery).FirstOrDefault();
                    if (OldQuery != null)
                    {
                        OldQuery.CustomerCount += 1;
                        _queryRepository.Save(OldQuery);
                    }
                }
                // اگر مشتری قبلی بود از مرحله قبل یکی کم و به مرحله جدید یکی اضافه کنذ
                else
                {
                    Infrastructure.Querying.Query oldQuery = new Infrastructure.Querying.Query();
                    Criterion crt1 = new Criterion("Level.ID", customerLevel.Customer.Level.ID, CriteriaOperator.Equal);
                    oldQuery.Add(crt1);
                    Model.Customers.Query OldQuery = _queryRepository.FindBy(oldQuery).FirstOrDefault();
                    OldQuery.CustomerCount -= 1;
                    _queryRepository.Save(OldQuery);

                    Infrastructure.Querying.Query newQuery = new Infrastructure.Querying.Query();
                    Criterion crt2 = new Criterion("Level.ID", request.NewLevelID, CriteriaOperator.Equal);
                    newQuery.Add(crt2);
                    Model.Customers.Query NewQuery = _queryRepository.FindBy(newQuery).FirstOrDefault();
                    NewQuery.CustomerCount += 1;
                    _queryRepository.Save(NewQuery);
                }

                #endregion

                #region Change Customer Level In Customer Table

                Customer customer = _customerRepository.FindBy(request.CustomerID);
                customer.Level          = _levelRepository.FindBy(request.NewLevelID);
                customer.LevelEntryDate = PersianDateTime.Now;
                _customerRepository.Save(customer);


                #endregion

                _uow.Commit();

                #region Sending Email

                string displayName = "ماهان نت";
                string subject;
                //List<string> recipients = new List<string>();
                GeneralResponse sendResponse = new GeneralResponse();


                // if OnEnterSendEmail is true
                if (customerLevel.Level.OnEnterSendEmail)
                {
                    email.ID             = Guid.NewGuid();
                    email.CreateDate     = PersianDateTime.Now;
                    email.CreateEmployee = customerLevel.CreateEmployee;
                    email.Customer       = customerLevel.Customer;
                    subject          = customer.Name;
                    email.Subject    = subject;
                    email.RowVersion = 1;

                    #region Validation

                    if (email.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in email.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    #endregion

                    #region Send Email

                    // Replacing:
                    string emailBody = ReplaceTemplate(customerLevel.Level.EmailText, customerLevel.Customer.ConvertToCustomerView());

                    email.Body = emailBody;

                    string recipient = email.Customer.Email;
                    if (recipient == null || recipient == string.Empty)
                    {
                        response.ErrorMessages.Add("برای مشتری مورد نظر هیچ ایمیلی در سیستم تعریف نشده است.");

                        return(response);
                    }

                    //===============  Threading:
                    EmailData emailData = new EmailData()
                    {
                        displayName = displayName,
                        body        = emailBody,
                        subject     = subject,
                        recipient   = recipient
                    };

                    Thread oThread = new Thread(SendEmailVoid);
                    oThread.Start(emailData);

                    #endregion

                    _emailRepository.Add(email);
                }

                #endregion

                #region Sending Sms

                if (customerLevel.Level.OnEnterSendSMS)
                {
                    Sms sms = new Sms();
                    sms.ID             = Guid.NewGuid();
                    sms.CreateDate     = PersianDateTime.Now;
                    sms.CreateEmployee = customerLevel.CreateEmployee;
                    //sms.Body = customerLevel.Level.SMSText;
                    sms.Customer   = customerLevel.Customer;
                    sms.RowVersion = 1;

                    #region Validation

                    if (sms.GetBrokenRules().Count() > 0)
                    {
                        foreach (BusinessRule businessRule in sms.GetBrokenRules())
                        {
                            response.ErrorMessages.Add(businessRule.Rule);
                        }

                        return(response);
                    }

                    #endregion

                    string smsBody = ReplaceTemplate(customerLevel.Level.SMSText, customerLevel.Customer.ConvertToCustomerView());

                    // Threading
                    SmsData smsData = new SmsData()
                    {
                        body = smsBody, phoneNumber = customerLevel.Customer.Mobile1
                    };
                    Thread oThread = new Thread(SendSmsVoid);
                    oThread.Start(smsData);

                    _smsRepository.Add(sms);
                }

                #endregion
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }