public GeneralResponse AddSeupportDeliverService(AddSupportDeliverServiceRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                SupportDeliverService supportDeliverService = new SupportDeliverService();

                supportDeliverService.ID             = Guid.NewGuid();
                supportDeliverService.DeliverDate    = request.DeliverDate;
                supportDeliverService.TimeInput      = request.TimeInput;
                supportDeliverService.TimeOutput     = request.TimeOutput;
                supportDeliverService.AmountRecived  = request.AmountRecived;
                supportDeliverService.Comment        = request.Comment;
                supportDeliverService.CreateDate     = PersianDateTime.Now;
                supportDeliverService.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                supportDeliverService.RowVersion     = 1;
                supportDeliverService.Support        = _supportRepository.FindBy(request.SupportID);

                #region چک کردن عدم وجود مورد ثبت شده

                if (supportDeliverService.Support.SupportDeliverService.Count() > 0)
                {
                    response.ErrorMessages.Add("برای هر پشتیبانی بیش از یک تحویل سرویس نمیتوانید ثبت کنید");
                    return(response);
                }

                #endregion

                SupportStatusRelation supportStatusRelation = _supportStatusRelationRepository.FindBy(request.SupportStatusID);
                supportDeliverService.Support.SupportStatus          = _supportStatusRepository.FindBy(supportStatusRelation.RelatedSupportStatus.ID);
                supportDeliverService.Support.Customer.SupportStatus = supportDeliverService.Support.SupportStatus;

                if (supportDeliverService.Support.SupportStatus.IsLastSupportState)
                {
                    supportDeliverService.Support.Closed = true;
                }

                _supportDeliverServiceRepository.Add(supportDeliverService);

                #region Send SMS

                if (supportDeliverService.Support.SupportStatus.SendSmsOnEnter)
                {
                    // Threading
                    SmsData smsData = new SmsData()
                    {
                        body = supportDeliverService.Support.SupportStatus.SmsText, phoneNumber = supportDeliverService.Support.Customer.Mobile1
                    };
                    Thread oThread = new Thread(SendSmsVoid);
                    oThread.Start(smsData);
                }

                #endregion

                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Exemplo n.º 2
0
        public GeneralResponse AddSupportQc(AddSupportQcRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                SupportQc supportQc = new SupportQc();

                supportQc.ID             = Guid.NewGuid();
                supportQc.CreateDate     = PersianDateTime.Now;
                supportQc.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                supportQc.Comment        = request.Comment;
                supportQc.ExpertBehavior = (SupportQc.State)request.ExpertBehavior;
                supportQc.ExpertCover    = (SupportQc.State)request.ExpertCover;
                supportQc.InputTime      = request.InputTime;
                if (string.IsNullOrEmpty(request.Comment))
                {
                    response.ErrorMessages.Add("افزودن توضیحات به فرم الزامیست.");
                    return(response);
                }
                supportQc.OutputTime                 = request.OutputTime;
                supportQc.RecivedCost                = request.RecivedCost;
                supportQc.SaleAndService             = (SupportQc.State)request.SaleAndService;
                supportQc.SendNotificationToCustomer = request.SendNotificationToCustomer;
                supportQc.SendNotificationToMaster   = request.SendNotificationToMaster;
                supportQc.RowVersion                 = 1;

                supportQc.Support = _supportRepository.FindBy(request.SupportID);


                #region چک کردن عدم وجود مورد ثبت شده

                if (supportQc.Support.SupportQc.Count() > 0)
                {
                    response.ErrorMessages.Add("برای هر پشتیبانی بیش از یک فرم QC نمیتوانید ثبت کنید");
                    return(response);
                }

                #endregion

                SupportStatusRelation supportStatusRelation = _supportStatusRelationRepository.FindBy(request.SupportStatusID);
                supportQc.Support.SupportStatus          = _supportStatusRepository.FindBy(supportStatusRelation.RelatedSupportStatus.ID);
                supportQc.Support.Customer.SupportStatus = supportQc.Support.SupportStatus;

                if (supportQc.Support.SupportStatus.IsLastSupportState)
                {
                    supportQc.Support.Closed = true;
                }

                _supportQcRepository.Add(supportQc);
                _uow.Commit();

                #region Send SMS

                if (supportQc.Support.SupportStatus.SendSmsOnEnter)
                {
                    // Threading
                    SmsData smsData = new SmsData()
                    {
                        body = supportQc.Support.SupportStatus.SmsText, phoneNumber = supportQc.Support.Customer.Mobile1
                    };
                    Thread oThread = new Thread(SendSmsVoid);
                    oThread.Start(smsData);
                }

                #endregion
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public GeneralResponse AddSupportTicketWaiting(AddSupportTicketWaitingRequest request, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                SupportTicketWaiting supportTicketwaiting = new SupportTicketWaiting();

                supportTicketwaiting.ID                         = Guid.NewGuid();
                supportTicketwaiting.CreateDate                 = PersianDateTime.Now;
                supportTicketwaiting.CreateEmployee             = _employeeRepository.FindBy(CreateEmployeeID);
                supportTicketwaiting.Comment                    = request.Comment;
                supportTicketwaiting.DateOfPersenceDate         = request.DateOfPersenceDate;
                supportTicketwaiting.InstallExpert              = _employeeRepository.FindBy(request.InstallExpertID);
                supportTicketwaiting.Selt                       = request.Selt;
                supportTicketwaiting.SendNotificationToCustomer = request.SendNotificationToCustomer;
                supportTicketwaiting.Snr                        = request.Snr;
                supportTicketwaiting.SourceWireCheck            = request.SourceWireCheck;
                supportTicketwaiting.Support                    = _supportRepository.FindBy(request.SupportID);
                supportTicketwaiting.TicketSubject              = request.TicketSubject;
                supportTicketwaiting.WireColor                  = request.WireColor;
                supportTicketwaiting.RowVersion                 = 1;



                SupportStatusRelation supportStatusRelation = _supportStatusRelationRepository.FindBy(request.SupportStatusID);
                supportTicketwaiting.Support.SupportStatus          = _supportStatusRepository.FindBy(supportStatusRelation.RelatedSupportStatus.ID);
                supportTicketwaiting.Support.Customer.SupportStatus = supportTicketwaiting.Support.SupportStatus;

                if (supportTicketwaiting.Support.SupportStatus.IsLastSupportState)
                {
                    supportTicketwaiting.Support.Closed = true;
                }

                _supportTicketWaitingRepository.Add(supportTicketwaiting);
                _uow.Commit();

                #region Send SMS

                if (supportTicketwaiting.Support.SupportStatus.SendSmsOnEnter)
                {
                    // Threading
                    SmsData smsData = new SmsData()
                    {
                        body = supportTicketwaiting.Support.SupportStatus.SmsText, phoneNumber = supportTicketwaiting.Support.Customer.Mobile1
                    };
                    Thread oThread = new Thread(SendSmsVoid);
                    oThread.Start(smsData);
                }

                #endregion
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add(ex.InnerException.Message);
                }
            }

            return(response);
        }