예제 #1
0
 /*****
  *
  * Update the state in the table
  * from the send command
  *
  * ****/
 public void changeState(Guid RequestId, StateCodes state)
 {
     using (var context = new MVCAppEntities())
     {
         /****
          * Update the row selected with
          * the new state                 * ***/
         var row = context.Paymessages.Where(x => x.EventId == RequestId).FirstOrDefault();
         if (row != null)
         {
             Paymessage new_row = new Paymessage();
             new_row.error = row.error;
             new_row.EventId = row.EventId;
             new_row.id = row.id;
             new_row.state = state.ToString();
             context.Entry(row).CurrentValues.SetValues(new_row);
             context.SaveChanges();
         }
     }
 }
예제 #2
0
        internal async Task InitAsync()
        {
            States.Clear();
            StateCodes stateCode        = StateCodes.AndamanNicobarIslands;
            string     districtCode     = null;
            string     pinCode          = null;
            string     parctitionerName = null;
            State      state            = null;

            Out("------------------- Search Configuration -------------------");

            for (int i = 0; i < 3; i++)
            {
                Out("Enter the state code: ");
                Out("(Enter the number by the left side of each state)", ConsoleColor.White);
                Out("Example: ' 02 ' (without quotes) which stands for 'HimachalPradesh'", ConsoleColor.White);

                foreach (StateCodes code in Enum.GetValues(typeof(StateCodes)))
                {
                    Out($"| {(int) code:D2}  |  {code.ToString()}", ConsoleColor.White);
                }

                string stateCodeString = In();

                if (string.IsNullOrEmpty(stateCodeString) || stateCodeString.Where(x => !char.IsDigit(x)).Count() > 0)
                {
                    Out("Entered value is invalid.");
                }

                stateCode = (StateCodes)Enum.Parse(typeof(StateCodes), stateCodeString);
                Out("Please wait... getting districts of the specified state...");
                state = await CacheStateAsync(stateCode).ConfigureAwait(false);

                if (state == null)
                {
                    Out("Failed to get the districts. Please reenter the state code.");
                    continue;
                }

                break;
            }

            Out("Enter district numerical code: ");
            Out("(the code on left side of the district name)", ConsoleColor.White);
            Out("(leave empty to display all practitioners in the state)", ConsoleColor.White);

            foreach (StateResponse.Districts district in state.Districts)
            {
                Out($"| {district.DistrictNumericalCode}  |  {district.DistrictName}", ConsoleColor.White);
            }

            districtCode = In();

            Out("Enter pin code of the location of which you want to display practitioners of: ");
            Out("(leave empty if you don't want to filter with pin code)", ConsoleColor.White);
            pinCode = In();

            Out("Enter the practitioner name: ");
            parctitionerName = InWithMessage("(Leave Empty to display all the practitioners in the location)", ConsoleColor.White);

            Out("------------------- Configuration Success -------------------");

            Logger.Info("Please wait while we fetch the required data from 'https://services.gst.gov.in/' ...");

            List <GstResponse.Practitioner> result = await RequestGstPractitionersAsync(parctitionerName, stateCode, districtCode, pinCode).ConfigureAwait(false);

            if (result != null)
            {
                Logger.Info("Successfully received the data!");

                IEnumerable <GstResponse.Practitioner> parti = result.Where(x => (StateCodes)Enum.Parse(typeof(StateCodes), x.StateCode) == stateCode);

                Logger.Info($"Found a total of '{parti.Count()}' practitioners from '{stateCode.ToString()}' state.");

                foreach (GstResponse.Practitioner p in parti)
                {
                    Out($"{p.EnrolmentNumber} | {p.PractitionerName}", ConsoleColor.White);
                }

                Logger.Info("Shall we save the received data in CSV file ? (y/n)");

                if (InBoolean(ConsoleKey.Y))
                {
                    StringBuilder lines = new StringBuilder();

                    foreach (GstResponse.Practitioner p in parti)
                    {
                        lines.AppendLine($"{p.EnrolmentNumber},{p.PractitionerName},{p.EmailID},{p.ContactNumber},{p.Address.BuildingNumber} {p.Address.BuildName} {p.Address.FlatNumber} {p.Address.Road} {p.Address.PinCode},{p.StateCode},{p.DistrictCode}");
                    }

                    ToFile(lines.ToString());
                }

                Logger.Info("All operations completed!");
                return;
            }

            Logger.Error("Failed to complete operations.");
            Logger.Error("Please restart the application.");
        }