public static string CreateNewUser(User user) { int newId; string query = @"INSERT INTO users (firstname, lastname,addresse, email, barcode) output INSERTED.[id] VALUES(@firstname, @lastname,@addresse, @email,@barcode); "; string barcodeGenerate = RandomString(29); string queryCheckUnique = connectionBaseUsers + "WHERE barcode LIKE @barcode"; bool alreadyExists = true; while (alreadyExists == true) { using (IDbConnection db = new SqlConnection(ConnectionHandler.getConnectionString())) alreadyExists = db.ExecuteScalar <bool>(queryCheckUnique, new { barcode = barcodeGenerate }); barcodeGenerate = RandomString(29); } user.barcode = barcodeGenerate; using (IDbConnection db = new SqlConnection(ConnectionHandler.getConnectionString())) newId = db.ExecuteScalar <int>(query, new { barcode = barcodeGenerate, addresse = user.addresse, firstname = user.firstname, lastname = user.lastname, email = user.email }); _ = EmailHandler.sentMailSentgridAsync("*****@*****.**", "new user generated", "new genereated user:"******" " + user.lastname, user.firstname + " " + user.lastname); sentRegMailToUser(user); return(barcodeGenerate); }
public static Product GetById(int id) { using (IDbConnection db = new SqlConnection(ConnectionHandler.getConnectionString())) return(db.QueryFirstOrDefault <Product>(connectionBase + " WHERE id=@id", new { id })); }
public static IEnumerable <Product> Get() { using (IDbConnection db = new SqlConnection(ConnectionHandler.getConnectionString())) return(db.Query <Product>(connectionBase)); }