public void AddLeadLog(string ticketNo, EnumPostingStatus status, string statusRemarks)
        {
            LeadLog log = new LeadLog();

            log.Scale_Ticket_No   = ticketNo;
            log.Status            = status.ToString();
            log.Status_Remarks    = statusRemarks;
            log.Active_Ind        = true;
            log.Created_Date      = DateTime.Now;
            log.Last_Updated_Date = DateTime.Now;
            log.Created_By        = "Admin";
            log.Updated_By        = "Admin";
            _leadLogLib.Add(log);
        }
Exemple #2
0
        public bool PostTickets()
        {
            try
            {
                string errorMsg = string.Empty;
                int    errorCode;
                if (!CheckLogin(out errorMsg))
                {
                    throw new Exception(errorMsg);
                }
                IEnumerable <Scale> scales = _rsmartService.GetPendingTickets();
                try
                {
                    foreach (var scale in scales)
                    {
                        IEnumerable <ScaleDetails>     scaleDetails     = _rsmartService.GetTicketItemsByTicketId(scale.ID);
                        IEnumerable <ScaleAttachments> scaleAttachments = _rsmartService.GetTicketAttachmentsByTicketId(scale.ID);
                        AddressBook partyPrimaryAddress = _rsmartService.GetAddressByPartyId(scale.Party_ID.ID);

                        Ticket t = new Ticket();
                        t = _rsmartService.MapTicketFromRsmartTicket(scale, scaleDetails, scaleAttachments, partyPrimaryAddress, t);


                        // Start transaction.
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions
                        {
                            IsolationLevel = IsolationLevel.Serializable
                        }))
                        {
                            string            statusRemarks = string.Empty;
                            EnumPostingStatus status        = EnumPostingStatus.Failed;
                            string            action        = "add";


                            SubmitTransaction(t, out errorMsg, out errorCode);

                            if (errorCode == 13)
                            {
                                action = "update";
                                TicketKey ticketKey = new TicketKey();
                                ticketKey.ticketnumber   = scale.Scale_Ticket_No;
                                ticketKey.ticketDateTime = scale.Created_Date.ToString();
                                UpdateTransaction(ticketKey, t, out errorMsg, out errorCode);
                            }

                            if (errorCode == 0)
                            {
                                status = EnumPostingStatus.Succeed;
                                _rsmartService.UpdateTicketStatus(scale);
                                statusRemarks = string.Format("Successfully {0} ticket# {1}", action, scale.Scale_Ticket_No);
                            }
                            else
                            {
                                statusRemarks = string.Format("Failed to {0} ticket# {1} due to '{2}'", action, scale.Scale_Ticket_No, errorMsg);
                            }

                            _rsmartService.AddLeadLog(scale.Scale_Ticket_No, status, statusRemarks);
                            scope.Complete();
                        }
                    }
                    TextFileLogger.Log(string.Format("{0}{1} ticket(s) posted on leads at {2}.", System.Environment.NewLine, scales.Count(), DateTime.Now.ToString()));
                }
                catch (Exception ex)
                {
                    ExceptionHandler.HandleException(ex, errorMsg);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex);
            }
            return(true);
        }