public Customer CreateCustomer(Customer customer)
 {
     try
     {
         customer.CreatedDate  = Convert.ToDateTime(DateTime.Now);
         customer.ModifiedDate = Convert.ToDateTime(DateTime.Now);
         _customer.InsertOne(customer);
         if (customer.Status == CustomerStatus.SUBMIT)
         {
             var dataCRMProcessing = new DataCRMProcessing
             {
                 CustomerId = customer.Id,
                 Status     = DataCRMProcessingStatus.InProgress
             };
             _dataCRMProcessingServices.CreateOne(dataCRMProcessing);
             if (customer.GreenType == GeenType.GreenC)
             {
                 var dataMCProcessing = new DataMCProcessing
                 {
                     CustomerId = customer.Id,
                     Status     = DataCRMProcessingStatus.InProgress
                 };
                 _dataMCProcessingServices.CreateOne(dataMCProcessing);
             }
         }
         return(customer);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         return(null);
     }
 }
        public DataCRMProcessing CreateOne(DataCRMProcessing dataCRM)
        {
            var newData = new DataCRMProcessing();

            try
            {
                _dataCRMProcessing.InsertOne(dataCRM);
                newData = dataCRM;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
            }
            return(newData);
        }
Example #3
0
 private void PushDataToCRM(Record dataCRM, string session, DataCRMProcessing dataCRMProcessing)
 {
     try
     {
         var client = new RestClient(Common.Constants.Url.CRMURL);
         client.Timeout = -1;
         var request = new RestRequest(Method.POST);
         request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
         request.AddParameter("_operation", "saveRecord");
         request.AddParameter("values", "" + JsonConvert.SerializeObject(dataCRM) + "");
         request.AddParameter("_session", "" + session + "");
         request.AddParameter("module", "Potentials");
         request.AddParameter("record", "13x55730");
         IRestResponse response = client.Execute(request);
         Console.WriteLine(response.Content);
         dataCRMProcessing.Status = Common.DataCRMProcessingStatus.Done;
         _dataCRMProcessingServices.UpdateByCustomerId(dataCRMProcessing.CustomerId, Common.DataCRMProcessingStatus.Done);
         _logger.LogInformation("User was pushed to CRM: {0} - Status: {1}", dataCRMProcessing.CustomerId, Common.DataCRMProcessingStatus.Done);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
     }
 }
        public long UpdateCustomer(Customer customer)
        {
            long updateCount = 0;

            try
            {
                string teamLead = "";
                string userName = "";
                string message  = "";
                string type     = "";

                dynamic prvCustomer = _customer.Find(c => c.Id == customer.Id).FirstOrDefault();
                var     currUser    = _userroleServices.GetUserRoleByUserName(customer.UserName);
                if (currUser != null)
                {
                    teamLead = currUser.TeamLead;
                }
                customer.ModifiedDate = Convert.ToDateTime(DateTime.Now);
                customer.CreatedDate  = prvCustomer.CreatedDate;
                updateCount           = _customer.ReplaceOne(c => c.Id == customer.Id, customer).ModifiedCount;

                if (customer.Status.ToUpper() == CustomerStatus.SUBMIT)
                {
                    // Update to CRM
                    var dataCRMProcessing = new DataCRMProcessing
                    {
                        CustomerId = customer.Id,
                        Status     = DataCRMProcessingStatus.InProgress
                    };
                    _dataCRMProcessingServices.CreateOne(dataCRMProcessing);
                    // Notification
                    userName = teamLead;
                    if (!String.IsNullOrEmpty(customer.Result?.Reason))
                    {
                        type    = NotificationType.Edit;
                        message = string.Format(Message.NotificationUpdate, customer.UserName, customer.Personal.Name);
                    }
                    else
                    {
                        type    = NotificationType.Add;
                        message = string.Format(Message.NotificationAdd, customer.UserName, customer.Personal.Name);
                    }
                }
                else if (customer.Status.ToUpper() == CustomerStatus.REJECT)
                {
                    userName = customer.UserName;
                    type     = NotificationType.TeamLeadReject;
                    message  = string.Format(Message.TeamLeadReject, teamLead, customer.Personal.Name);
                }
                else if (customer.Status.ToUpper() == CustomerStatus.APPROVE)
                {
                    // send data to MC
                    if (customer.GreenType == GeenType.GreenC)
                    {
                        var dataMCProcessing = new DataMCProcessing
                        {
                            CustomerId = customer.Id,
                            Status     = DataCRMProcessingStatus.InProgress
                        };
                        _dataMCProcessingServices.CreateOne(dataMCProcessing);
                    }
                    userName = customer.UserName;
                    type     = NotificationType.TeamLeadApprove;
                    message  = string.Format(Message.TeamLeadApprove, teamLead, customer.Personal.Name);
                }

                if (message != "")
                {
                    var objNoti = new Notification
                    {
                        green    = GeenType.GreenC,
                        recordId = customer.Id,
                        isRead   = false,
                        type     = type,
                        userName = userName,
                        message  = message,
                        createAt = Convert.ToDateTime(DateTime.Today.ToLongDateString())
                    };
                    _notificationServices.CreateOne(objNoti);
                }
            }
            catch (Exception ex)
            {
                updateCount = -1;
                _logger.LogError(ex, ex.Message);
            }
            return(updateCount);
        }