Ejemplo n.º 1
0
        public PersonProfile GetPersonProfileByIPCode(int ipCode)
        {
            List<PersonProfile> personProfiles = new List<PersonProfile>();

            Console.WriteLine(string.Format("BEGIN Get PersonProfile data from SQL Server"));
            Console.WriteLine();

            using (var context = new RTPContext())
            {
                personProfiles = context.PersonProfiles.SqlQuery("SELECT IPCode, ProfileTypeCode, SequenceNumber, FirstName, LastName FROM PersonProfile WHERE StatusCode = 1 AND IPCode = " + ipCode.ToString() + " ORDER BY UpdateDate DESC").ToList<PersonProfile>();
            }

            Console.WriteLine(string.Format("END Get PersonProfile data from SQL Server"));
            Console.WriteLine();

            return personProfiles.FirstOrDefault();
        }
Ejemplo n.º 2
0
        public void ProcessOrders()
        {
            int batchSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"].ToString());

            Console.Write(string.Format("Batch Size: {0}", batchSize));
            Console.ReadLine();
            Console.WriteLine();

            EConnectCreateOrderResponse response = null;
            List<RFIDPassMediaReissueStage> orders = GetRFIDPassMediaReissueStageByStatus(Enums.OrderStatus.Pending);
            List<RFIDPassMediaReissueDetailStage> orderDetails = null;

            foreach (RFIDPassMediaReissueStage order in orders)
            {
                orderDetails = GetRFIDPassMediaReissueDetailStageByPrimaryIPCode(order.PrimaryIPCode);

                //Process request
                try
                {
                    response = ProcessRequest(orderDetails);
                }
                catch(Exception ex)
                {
                    response = new EConnectCreateOrderResponse();
                    response.ResponseCode = 1;
                    response.ResponseMessage = ex.Message;
                }

                //Update DB
                try
                {
                    using (var context = new RTPContext())
                    {
                        order.StatusID = response.ResponseCode == 0 ? Enums.OrderStatus.Processed.GetHashCode() : Enums.OrderStatus.Error.GetHashCode();

                        //Parent record is success but there was an error with at least one of the household users
                        if (order.StatusID == Enums.OrderStatus.Processed.GetHashCode() && response.EConnectFulfillOrderResponse.EConnectFulfillOrderDetailResponses.Where(d => d.ResponseCode != 0).Count() > 0)
                        {
                            order.StatusID = Enums.OrderStatus.PartialError.GetHashCode();
                        }

                        order.UpdateDate = DateTime.Now;
                        order.ErrorMessage = response.ResponseMessage;
                        if (response.SupplierOrderID > 0)
                        {
                            order.OrderID = response.SupplierOrderID;
                        }

                        context.RFIDPassMediaReissueStages.Attach(order);
                        context.Entry(order).State = EntityState.Modified;

                        //If null then the order was never created so don't update RFIDPassMediaReissueDetailStage table
                        if (response.EConnectFulfillOrderResponse != null)
                        {
                            foreach (RFIDPassMediaReissueDetailStage detail in orderDetails)
                            {
                                EConnectFulfillOrderDetailResponse responseDetail = response.EConnectFulfillOrderResponse.EConnectFulfillOrderDetailResponses.Where(d => d.IPCode == detail.IPCode).FirstOrDefault();

                                detail.ErrorMessage = responseDetail.ResponseMessage;
                                detail.StatusID = responseDetail.ResponseCode == 0 ? Enums.OrderStatus.Processed.GetHashCode() : Enums.OrderStatus.Error.GetHashCode();

                                context.RFIDPassMediaReissueDetailStages.Attach(detail);
                                context.Entry(detail).State = EntityState.Modified;
                            }
                        }

                        context.SaveChanges();

                        if (order.StatusID == Enums.OrderStatus.Processed.GetHashCode())
                        {
                            Console.WriteLine(string.Format("SUCCESS for PrimaryIPCode: {0}", order.PrimaryIPCode));
                        }
                        else
                        {
                            Console.WriteLine(string.Format("ERROR for PrimaryIPCode: {0}", order.PrimaryIPCode));
                        }
                        Console.WriteLine();
                    }
                }
                catch(Exception ex)
                {
                    string message = ex.Message + "\r\n" + ex.StackTrace + "\r\n DistributorOrderID: " + (string.IsNullOrEmpty(response.DistributorOrderID) ? "" : response.DistributorOrderID);
                    message += "\r\n PrimaryIPCode:" + order.PrimaryIPCode.ToString();

                  //  System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\RFID.Order.Console_ERROR.txt", true);
                   // file.WriteLine(message);
                    //file.Close();

                    //throw ex;

                    Console.WriteLine("Exception during SQL save: " + message);
                    Console.ReadLine();
                    //Console.WriteLine();
                }
            }
        }
Ejemplo n.º 3
0
        private List<RFIDPassMediaReissueStage> GetRFIDPassMediaReissueStageByStatus(Enums.OrderStatus status)
        {
            int batchSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"].ToString());

            List<RFIDPassMediaReissueStage> orders = new List<RFIDPassMediaReissueStage>();

            Console.WriteLine(string.Format("BEGIN Get RFIDPassMediaReissueStage data from SQL Server"));
            Console.WriteLine();

            using (var context = new RTPContext())
            {
                orders = context.RFIDPassMediaReissueStages.SqlQuery("SELECT TOP " + batchSize.ToString() + " * FROM RFIDPassMediaReissueStage WHERE StatusID = " + status.GetHashCode().ToString()).ToList<RFIDPassMediaReissueStage>();
            }

            Console.WriteLine(string.Format("END Get RFIDPassMediaReissueStage data from SQL Server"));
            Console.WriteLine();

            return orders;
        }
Ejemplo n.º 4
0
        private List<RFIDPassMediaReissueDetailStage> GetRFIDPassMediaReissueDetailStageByPrimaryIPCode(int primaryIPCode)
        {
            List<RFIDPassMediaReissueDetailStage> orderDetails = new List<RFIDPassMediaReissueDetailStage>();

            Console.WriteLine(string.Format("BEGIN Get RFIDPassMediaReissueDetailStage data  (PrimaryIPCode: {0} ) from SQL Server", primaryIPCode));
            Console.WriteLine();

            using (var context = new RTPContext())
            {
                orderDetails = context.RFIDPassMediaReissueDetailStages.SqlQuery("SELECT * FROM RFIDPassMediaReissueDetailStage WHERE PrimaryIPCode = " + primaryIPCode.ToString()).ToList<RFIDPassMediaReissueDetailStage>();
            }

            Console.WriteLine(string.Format("END Get RFIDPassMediaReissueDetailStage data  (PrimaryIPCode: {0} ) from SQL Server", primaryIPCode));
            Console.WriteLine();

            return orderDetails;
        }