//public static string GetURL() //{ // string URL = ""; // Random rand = new Random(); // for (int i = 0; i < characters.Count; i++) // { // int random = rand.Next(0, characters.Count); // URL += characters[random].ToString(); // } // return URL; //} public void AddNewShortCharcter() { ShortCharacters shortcharcters = new ShortCharacters(); ShortnerContext _context = new ShortnerContext(); var result = _context.ShortCharacters.Add(shortcharcters); int Return = _context.SaveChanges(); }
public static string GetURL() { string URL = ""; Random rand = new Random(); // run the loop till I get a string of 10 characters //posibility of characters count int posibilitycount = characters.Count; for (int i = 0; i < characters.Count - 1; i++) { posibilitycount = posibilitycount * characters.Count; } //Add new character in list int newcharposition = 0; if ((posibilitycount - 5) < count) { newcharposition = characters.Count - 4; char newchar = characters[newcharposition]; characters.Add(newchar); //Add new character ShortCharacters shortcharacter = new ShortCharacters(); shortcharacter.Id = 1; var shortcharentity = _context.ShortCharacters.Find(shortcharacter.Id); shortcharentity.Characters = shortcharentity.Characters + "," + newchar; _context.Entry(shortcharentity).CurrentValues.SetValues(shortcharentity); _context.SaveChanges(); } for (int i = 0; i < characters.Count; i++) { // Get random numbers, to get either a character or a number... //int random = rand.Next(0, 3); int random = rand.Next(0, characters.Count); URL += characters[random].ToString(); } return(URL); }
public bool SaveAll() { int Return = _ctx.SaveChanges(); return(Return > 0); }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }