/* * Terse demonstration of processing commandline input provided by the user * */ private static void processUserInput(string[] args) { if (args.Length != 2 || (!args[0].Equals("verify") && !args[0].Equals("complete"))) { Console.WriteLine("\nIncorrect arguments.\n"); Console.WriteLine("Usage: dotnet ExampleUser.dll {verify|complete} gmn_data\n"); Environment.Exit(1); } try { if (args[0].Equals("verify")) { bool valid = GMN.VerifyCheckCharacters(args[1]); Console.WriteLine("The check characters are " + (valid ? "valid" : "NOT valid")); Environment.Exit(valid ? 0:1); } else // complete { Console.WriteLine(GMN.AddCheckCharacters(args[1])); Environment.Exit(0); } } catch (GS1Exception e) { Console.WriteLine("Error: " + e.Message); Environment.Exit(1); } }
public ActionResult PostGoingEvent(GMN goingevent) { string userId = User.Claims.First(c => c.Type == "UserId").Value; EventsGoPeople eventsGo = new EventsGoPeople(); var gopeoplecon = _context.eventsGoPeoples.ToList(); var count = 0; foreach (var item in gopeoplecon) { if (item.UserId.Equals(userId)) { if (item.TaskId == goingevent.TaskId) { item.GMN = goingevent.Type; _context.Entry(item).State = EntityState.Modified; try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(NotFound()); } count = 1; } //_context.Entry(goingevent).State = EntityState.Modified; //try //{ // _context.SaveChangesAsync(); //} //catch (DbUpdateConcurrencyException) //{ // return NotFound(); //} } } if (count == 0) { eventsGo.UserId = userId; eventsGo.TaskId = goingevent.TaskId; eventsGo.GMN = goingevent.Type; _context.eventsGoPeoples.Add(eventsGo); _context.SaveChanges(); } return(Ok(goingevent)); }
static void Main(string[] args) { /* * User has provided commandline arguments. We tuck this code out of * the way for clarity and demonstrate some simpler cases first. * */ if (args.Length > 0) { processUserInput(args); } /* * Non-interactive demonstration * */ Console.WriteLine("\nOutput from non-interactive demonstration"); Console.WriteLine("*****************************************\n"); /* * Example: GS1.GMN.VerifyCheckCharacters * * Verifying the check characters of a GMN. * */ try { string gmn = "1987654Ad4X4bL5ttr2310c2K"; // Valid GMN based on example from the Gen Specs // string gmn = "1987654Ad4X4bL5ttr2310cZZ"; // Invalid: Bad check digits // Examples that raise exceptions: // // string gmn = "1987654Ad4X4bL5ttr2310c2KZ"; // Exception: Too long // string gmn = "12345AB"; // Exception: Too short // string gmn = "ABC7654Ad4X4bL5ttr2310cZZ"; // Exception: Doesn't start with five digits // string gmn = "12345£££d4X4bL5ttr2310cZZ"; // Exception: Contains characters outside of CSET 82 /* Call the GS1.VerifyCheckCharacters helper */ bool valid = GMN.VerifyCheckCharacters(gmn); if (valid) { Console.WriteLine("This GMN has correct check characters: " + gmn); } else { Console.WriteLine("This GMN has incorrect check characters: " + gmn); } Console.WriteLine(); } catch (GS1Exception e) { Console.Error.WriteLine("Something went wrong: " + e.Message); System.Environment.Exit(1); } /* * Example: GS1.GMN.AddCheckCharacters * * Adding the check characters to an incomplete GMN. * */ try { string partialGMN = "1987654Ad4X4bL5ttr2310c"; // Based on example from the Gen Specs // Examples that raise exceptions: // // string partialGMN = "1987654Ad4X4bL5ttr2310cX"; // Exception: Too long // string partialGMN = "12345"; // Exception: Too short // string partialGMN = "ABC7654Ad4X4bL5ttr2310c"; // Exception: Doesn't start with five digits // string partialGMN = "12345£££d4X4bL5ttr2310c"; // Exception: Contains characters outside of CSET 82 /* Call the GS1.GMN.AddCheckCharacters helper */ string gmn = GMN.AddCheckCharacters(partialGMN); Console.WriteLine("Partial: " + partialGMN); Console.WriteLine("Full GMN: " + gmn); Console.WriteLine(); } catch (GS1Exception e) { Console.Error.WriteLine("Something went wrong: " + e.Message); System.Environment.Exit(1); } /* * Example: GS1.GMN.CheckCharacters * * Returning just the check characters, then completing the GMN * */ try { string partialGMN = "1987654Ad4X4bL5ttr2310c"; // Based on example from the Gen Specs /* Call the GS1.GMN.CheckCharacters helper */ string checkCharacters = GMN.CheckCharacters(partialGMN); Console.WriteLine("Partial: " + partialGMN); Console.WriteLine("Checks: " + checkCharacters); // Contatenate to produce the complete GMN string gmn = partialGMN + checkCharacters; Console.WriteLine("Full GMN: " + gmn); Console.WriteLine(); } catch (GS1Exception e) { Console.Error.WriteLine("Something went wrong: " + e.Message); System.Environment.Exit(1); } /* * Interactive demonstration * */ Console.WriteLine("\nInteractive demonstration"); Console.WriteLine("*************************"); while (true) { Console.WriteLine("\nPlease select an option:\n"); Console.WriteLine(" c - Complete a partial GMN by adding check digits"); Console.WriteLine(" v - Verify the check digits of a complete GMN"); Console.WriteLine(" cf - Complete partial GMNs supplied on each line of a file"); Console.WriteLine(" vf - Verify complete GMNs supplied on each line of a file"); Console.WriteLine(" q - Quit"); Console.Write("\nEnter option (c/v/cf/vf/q)? "); string opt = Console.ReadLine(); // Quit if (opt.Equals("q")) { break; } // Verify a GMN if (opt.Equals("v")) { try { Console.Write("\nPlease supply a GMN: "); String gmn = Console.ReadLine(); bool valid = GMN.VerifyCheckCharacters(gmn); Console.WriteLine("Outcome: " + (valid ? "*** Valid ***" : "*** Not valid ***")); } catch (GS1Exception e) { Console.WriteLine("Error with input: " + e.Message); } continue; } // Complete a partial GMN if (opt.Equals("c")) { try { Console.Write("\nPlease supply a partial GMN to complete: "); String gmn = Console.ReadLine(); String complete = GMN.AddCheckCharacters(gmn); Console.WriteLine("Complete GMN: " + complete); } catch (GS1Exception e) { Console.WriteLine("Error with input: " + e.Message); } continue; } // Operations line by line on a file if (opt.Equals("cf") || opt.Equals("vf")) { try { Console.Write("\nPlease supply a filename: "); string filename = Console.ReadLine(); System.IO.StreamReader reader = new System.IO.StreamReader(filename); string linein, lineout; while ((linein = reader.ReadLine()) != null) { try { if (opt.Equals("cf")) { lineout = GMN.CheckCharacters(linein); } else { // vf lineout = GMN.VerifyCheckCharacters(linein) ? "*** Valid ***" : "*** Not valid ***"; } } catch (GS1Exception e) { lineout = e.Message; } Console.WriteLine(linein + " : " + lineout); } reader.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } continue; } } return; }